Discussion:
Invoking a function from a list of functions
Tim Johnson
2018-11-08 23:01:25 UTC
Permalink
Given a list of functions:
(setq funcs '(scroll-up-line scroll-down-line))

And assuming that these functions have a similar argument list,
I can invoke a function as:

(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)

That approach is sufficient for my needs at the moment, an example
of which might be to cycle through color themes invoked by my own
functions.

However, in the quest for futher edification I'd welcome URLs to
documentation or discussion, as well as any contributions other
emacsen might choose to make. Keywords also.

I had a heck of a time getting relevant responses from google. I
actually don't know what keywords to search with.

thanks
GNU Emacs 26.1 GTK+ Version, Ubuntu 16.04
--
Tim Johnson
http://www.tj49.com
Eric Abrahamsen
2018-11-09 01:25:30 UTC
Permalink
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
That approach is sufficient for my needs at the moment, an example
of which might be to cycle through color themes invoked by my own
functions.
However, in the quest for futher edification I'd welcome URLs to
documentation or discussion, as well as any contributions other
emacsen might choose to make. Keywords also.
I had a heck of a time getting relevant responses from google. I
actually don't know what keywords to search with.
It isn't clear to me, at least, what else you might be trying to achieve
here. Is it more accurately selecting a function from within a list,
using a keyword? Or cycling through functions in a list?

You'll have a heck of a time getting relevant responses on this list,
too, unless you tell us what you're after! :)
Tim Johnson
2018-11-09 06:03:02 UTC
Permalink
Post by Eric Abrahamsen
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
That approach is sufficient for my needs at the moment, an example
of which might be to cycle through color themes invoked by my own
functions.
However, in the quest for futher edification I'd welcome URLs to
documentation or discussion, as well as any contributions other
emacsen might choose to make. Keywords also.
I had a heck of a time getting relevant responses from google. I
actually don't know what keywords to search with.
It isn't clear to me, at least, what else you might be trying to achieve
here. Is it more accurately selecting a function from within a list,
using a keyword? Or cycling through functions in a list?
You'll have a heck of a time getting relevant responses on this list,
too, unless you tell us what you're after! :)
Thanks for the reply Eric: As I demonstrated on my code examples,
I know how to extract a function from a list and invoke it.

... So that's done. Now, iterating thru a list of functions that
might invoke a particular color theme is an example of such an
application and I think I grok that.

What I am interested in is further discussion whether it be from
replies to this topic or more general topics in this area. I'm
restating that I've had a difficult time finding results from
google.

--------------------------------------------------------
That is probably because I don't know the right keywords
or domain-specific terms to use
--------------------------------------------------------

This isn't just difficult for emacs/elisp, I've found it difficult
for python functions invoked from lists or dictionaries. (altho
I've employed such methods for years in python)

So I'm sorry to be so unclear: let me restate the nut and kernel
of my question:

If I wished to further research this topic using a search engine
what are the keywords that I might feed to google?

I hope that you now understand what I'm after.

cheers
--
Tim Johnson
http://www.tj49.com
Marcin Borkowski
2018-11-09 10:30:25 UTC
Permalink
Post by Tim Johnson
Post by Eric Abrahamsen
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
That approach is sufficient for my needs at the moment, an example
of which might be to cycle through color themes invoked by my own
functions.
However, in the quest for futher edification I'd welcome URLs to
documentation or discussion, as well as any contributions other
emacsen might choose to make. Keywords also.
I had a heck of a time getting relevant responses from google. I
actually don't know what keywords to search with.
It isn't clear to me, at least, what else you might be trying to achieve
here. Is it more accurately selecting a function from within a list,
using a keyword? Or cycling through functions in a list?
You'll have a heck of a time getting relevant responses on this list,
too, unless you tell us what you're after! :)
Thanks for the reply Eric: As I demonstrated on my code examples,
I know how to extract a function from a list and invoke it.
... So that's done. Now, iterating thru a list of functions that
might invoke a particular color theme is an example of such an
application and I think I grok that.
What I am interested in is further discussion whether it be from
replies to this topic or more general topics in this area. I'm
restating that I've had a difficult time finding results from
google.
--------------------------------------------------------
That is probably because I don't know the right keywords
or domain-specific terms to use
--------------------------------------------------------
This isn't just difficult for emacs/elisp, I've found it difficult
for python functions invoked from lists or dictionaries. (altho
I've employed such methods for years in python)
So I'm sorry to be so unclear: let me restate the nut and kernel
If I wished to further research this topic using a search engine
what are the keywords that I might feed to google?
I hope that you now understand what I'm after.
Just guessing:

first-class functions/closures?
functions as data?
dynamic function calling?

Hth,
--
Marcin Borkowski
http://mbork.pl
Noam Postavsky
2018-11-09 11:52:46 UTC
Permalink
Post by Tim Johnson
I know how to extract a function from a list and invoke it.
... So that's done. Now, iterating thru a list of functions that
might invoke a particular color theme is an example of such an
application and I think I grok that.
What I am interested in is further discussion whether it be from
replies to this topic or more general topics in this area.
If I wished to further research this topic
What is "this topic"? Extracting a value from a list? Calling a function?
Van L
2018-11-09 13:12:37 UTC
Permalink
Post by Noam Postavsky
What is "this topic"? Extracting a value from a list? Calling a function?
Given a list of functions (fa fb fc ...), pick one to call?
Tim Johnson
2018-11-09 16:14:30 UTC
Permalink
Post by Noam Postavsky
Post by Tim Johnson
I know how to extract a function from a list and invoke it.
... So that's done. Now, iterating thru a list of functions that
might invoke a particular color theme is an example of such an
application and I think I grok that.
What I am interested in is further discussion whether it be from
replies to this topic or more general topics in this area.
If I wished to further research this topic
What is "this topic"? Extracting a value from a list? Calling a function?
Yup.
--
Tim Johnson
http://www.tj49.com
Yuri Khan
2018-11-09 14:16:52 UTC
Permalink
Post by Tim Johnson
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
What I am interested in is further discussion whether it be from
replies to this topic or more general topics in this area. I'm
restating that I've had a difficult time finding results from
google.
--------------------------------------------------------
That is probably because I don't know the right keywords
or domain-specific terms to use
--------------------------------------------------------
This isn't just difficult for emacs/elisp, I've found it difficult
for python functions invoked from lists or dictionaries. (altho
I've employed such methods for years in python)
If I wished to further research this topic using a search engine
what are the keywords that I might feed to google?
The term you are looking for is “first-class functions”. This refers
to passing functions as arguments to other functions, returning
functions out of functions, storing functions in variables and data
structures, and otherwise treating functions the same way as other
values.

A related term, but from object-oriented programming, is “virtual
method”. This is a narrower concept, that you might want to call
different implementations of a function depending on the type of its
argument.
Tim Johnson
2018-11-09 16:22:01 UTC
Permalink
Post by Yuri Khan
Post by Tim Johnson
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
What I am interested in is further discussion whether it be from
replies to this topic or more general topics in this area. I'm
restating that I've had a difficult time finding results from
google.
--------------------------------------------------------
That is probably because I don't know the right keywords
or domain-specific terms to use
--------------------------------------------------------
This isn't just difficult for emacs/elisp, I've found it difficult
for python functions invoked from lists or dictionaries. (altho
I've employed such methods for years in python)
If I wished to further research this topic using a search engine
what are the keywords that I might feed to google?
The term you are looking for is “first-class functions”. This refers
to passing functions as arguments to other functions, returning
functions out of functions, storing functions in variables and data
structures, and otherwise treating functions the same way as other
values.
That is exactly correct, yet I find nothing on this topic using
“first-class functions” as a keyword/phrase.

This obscurity is shared by python. The 'list-or-dictionary-of- functions
approach that I've used for years in python is just as
hard to search for. I believe I also used that tactic in C back
when I did GUI programming, but it has been so very long and I'm so
very retired ... :)
Post by Yuri Khan
A related term, but from object-oriented programming, is “virtual
method”. This is a narrower concept, that you might want to call
different implementations of a function depending on the type of its
argument.
thanks
--
Tim Johnson
http://www.tj49.com
Stefan Monnier
2018-11-09 16:37:55 UTC
Permalink
Post by Tim Johnson
That is exactly correct, yet I find nothing on this topic using
“first-class functions” as a keyword/phrase.
I'm not sure exactly what kind of information you're looking for about
that, but maybe other related keywords might be "indirect function call"
(i.e. `funcall`) and "higher-order function" (which is the term used to
denote the functions that manipulate other functions, such as `mapcar`).


Stefan
Ihor Radchenko
2018-11-09 07:09:00 UTC
Permalink
All the strength of `mapc`, `mapcar`, `reduce` and other list functions
is in your hands.

For example,
#+begin_src emacs-slip
(setq funclist (mapcar #'symbol-function '(forward-line forward-char)))
(mapc #'funcall funclist)
(cl-mapc #'funcall funclist (make-list (length funclist) 2))
#+end_src

You can also take a look at =dash.el=. There are many useful list
functions there.

Best,
Ihor
Post by Tim Johnson
Post by Eric Abrahamsen
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
That approach is sufficient for my needs at the moment, an example
of which might be to cycle through color themes invoked by my own
functions.
However, in the quest for futher edification I'd welcome URLs to
documentation or discussion, as well as any contributions other
emacsen might choose to make. Keywords also.
I had a heck of a time getting relevant responses from google. I
actually don't know what keywords to search with.
It isn't clear to me, at least, what else you might be trying to achieve
here. Is it more accurately selecting a function from within a list,
using a keyword? Or cycling through functions in a list?
You'll have a heck of a time getting relevant responses on this list,
too, unless you tell us what you're after! :)
Thanks for the reply Eric: As I demonstrated on my code examples,
I know how to extract a function from a list and invoke it.
... So that's done. Now, iterating thru a list of functions that
might invoke a particular color theme is an example of such an
application and I think I grok that.
What I am interested in is further discussion whether it be from
replies to this topic or more general topics in this area. I'm
restating that I've had a difficult time finding results from
google.
--------------------------------------------------------
That is probably because I don't know the right keywords
or domain-specific terms to use
--------------------------------------------------------
This isn't just difficult for emacs/elisp, I've found it difficult
for python functions invoked from lists or dictionaries. (altho
I've employed such methods for years in python)
So I'm sorry to be so unclear: let me restate the nut and kernel
If I wished to further research this topic using a search engine
what are the keywords that I might feed to google?
I hope that you now understand what I'm after.
cheers
--
Tim Johnson
http://www.tj49.com
Andreas Röhler
2018-11-09 08:58:53 UTC
Permalink
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
That approach is sufficient for my needs at the moment, an example
of which might be to cycle through color themes invoked by my own
functions.
However, in the quest for futher edification I'd welcome URLs to
documentation or discussion, as well as any contributions other
emacsen might choose to make. Keywords also.
I had a heck of a time getting relevant responses from google. I
actually don't know what keywords to search with.
thanks
GNU Emacs 26.1 GTK+ Version, Ubuntu 16.04
Maybe that way:

(defun foo ()
(message "%s" "foo"))

(defun bar ()
(message "%s" "bar"))

(setq my-list-of-functions (list 'foo 'bar))

(funcall (nth 1 my-list-of-functions))

;;;;;

The point is to hand over functions as symbols, not their value
Tim Johnson
2018-11-09 16:24:31 UTC
Permalink
Post by Andreas Röhler
Post by Tim Johnson
(setq funcs '(scroll-up-line scroll-down-line))
And assuming that these functions have a similar argument list,
(funcall (nth 1 funcs))
;; or optionally
(funcall (nth 1 funcs) 2)
That approach is sufficient for my needs at the moment, an example
of which might be to cycle through color themes invoked by my own
functions.
However, in the quest for futher edification I'd welcome URLs to
documentation or discussion, as well as any contributions other
emacsen might choose to make. Keywords also.
I had a heck of a time getting relevant responses from google. I
actually don't know what keywords to search with.
thanks
GNU Emacs 26.1 GTK+ Version, Ubuntu 16.04
(defun foo ()
(message "%s" "foo"))
(defun bar ()
(message "%s" "bar"))
(setq my-list-of-functions (list 'foo 'bar))
(funcall (nth 1 my-list-of-functions))
;;;;;
The point is to hand over functions as symbols, not their value
And in Python, if you evaluate a function without the succeeding
parens: foo vs. foo()
you get an address. Same with C/C++ - if I recall correctly.
--
Tim Johnson
http://www.tj49.com
Rusi
2018-11-12 05:39:21 UTC
Permalink
Stefan and Yuri have pointed you to the search terms “higher order” and “first class” functions. The wider umbrella term is functional programming (FP).
Unfortunately this has become a cult with more malarkey than stuff of late especially after increasing mainstreaming of the FP language Haskell.
IOW there is the irony: from 50 to 25 years ago when FP was academic arcana, the ideas were more accessible than today when the direction invariably tilts towards Haskell: which is somewhat like using a missile to kill a fly.
Me: After having tried many options for teaching programming, Ive personally returned to gofer http://blog.languager.org/2014/09/pugofer.html which is a tiny early Haskell dialect, better for pedagogic purposes than the current behemoth: Some reasons: https://stackoverflow.com/questions/25855507/are-typeclasses-essential/25880674#25880674

But while gofer is ok for students under my supervision it is not a reasonable suggestion across the net

Some more generally reasonable/accessible suggestions:

1. Scheme is very much a lisp (except the Lisp-1 Lisp-2 minor mess https://en.wikipedia.org/wiki/Common_Lisp#The_function_namespace )
and unlike (E)Lisp tries hard to be a propah FPL.
The original scheme text https://mitpress.mit.edu/sites/default/files/sicp/index.html is considered a programming classic by many.
I dont like it much -- http://blog.languager.org/2013/08/applying-si-on-sicp.html shows why scheme though more powerful than FPLs is not properly appreciated even by its authors. Felleisen and Friedman I much prefer to SICP
https://www.htdp.org/2003-09-26/Book/
https://www.cs.unm.edu/~williams/cs357/springer-friedman.pdf

2. APL When we were kids Lisp and APL were the two defacto FPLs.
Today Lisp has stopped being considered an FPL
http://blog.languager.org/2015/04/cs-history-1.html

And APL has fallen off the radar... unfortunate. From your single example — (funcall (nth 1 funcs)) — I assume you are sensing that short expressions can be amazingly powerful and want to learn how to do more of that. Look at https://aplwiki.com/FinnAplIdiomLibrary for more such APL examples [Beware! Head can explode]

3. Python: CS degree students it's reasonable to push through them a dozen different languages so that they understand different paradigms in their most optimal setting. People self learning or with less time etc this may be unpleasant/formidable. And since you seem familiar with python there are also these two python options.
3a SICP in Python
https://wizardforcel.gitbooks.io/sicp-in-python/content/
http://www-inst.eecs.berkeley.edu/~cs61a/sp12/book/
3b Functional programming in python https://www.amazon.com/Functional-Python-Programming-Steven-Lott/dp/1784396990
[Disclaimer I have not delved into either of these so you spend your time at your risk]

Summary: If you wanted to learn Portuguese you could do it anywhere — NY, London Delhi Tokyo. However staying in Lisbon or Rio de Janeiro will give you more success (presumably!). Python copied its list comprehensions from haskell so in principle one should be able to write (most) Haskell comprehensions in python. But in the python world you will find universal dissuasion — "comprehensions are hard; first learn to write for-loops..." etc.
So paradoxically the best way to do comprehensions in python is by learning them out of python… Likewise FP in (E)Lisp

tl;dr: ‘(funcall (nth 1 funcs)) ’ is an example of FP style. Lisp/python can be used (for the most part) as an FPL. The cultural questions are the bigger impediment than the technical/factual ones

FP can be language independent… may be too laconic for a beginner! Consider these a list of search terms.

http://blog.languager.org/2012/10/functional-programming-lost-booty.html
http://blog.languager.org/2015/06/functional-programming-moving-target.html
Stefan Monnier
2018-11-12 15:19:47 UTC
Permalink
Post by Rusi
http://blog.languager.org/2013/08/applying-si-on-sicp.html shows why scheme
Indeed, `quote` is crucial and while trivial to implement for Scheme,
it's far from trivial in general (see "cross stage persistence" for
example).
Post by Rusi
And APL has fallen off the radar... unfortunate.
There's a bit of renewed (academic) interest, tho. Not exactly in APL,
but in array languages of the same family (i.e. using the same concepts but
without the exotic character set).

See for example http://www.ccs.neu.edu/home/pete/research/esop-2014.html


Stefan
Rusi
2018-11-16 02:48:53 UTC
Permalink
This post might be inappropriate. Click to display it.
James K. Lowden
2018-11-16 16:40:11 UTC
Permalink
On Thu, 15 Nov 2018 18:48:53 -0800 (PST)
Post by Rusi
Post by Stefan Monnier
See for example
http://www.ccs.neu.edu/home/pete/research/esop-2014.html
Interesting!
| The array-computational model pioneered by
| Iverson?s languages APL and J offers a simple
Yes. IMO array operators and orthogonal persistence are two very
underappreciated language design features.
Post by Rusi
Whenever a major organization develops a new system as an official
standard for X, the primary result is the widespread adoption of some
simpler system as a de facto standard for X.
Yes, but his examples don't hold water
Post by Rusi
The PL/I project by IBM and SHARE resulted in
Fortran and COBOL
PL/1 post-dates Cobol by at least 7 years. By the time PL/1 was
available, Cobol was already commercially successful. What use did the
Cobol programmer have for PL/1? And what evidence that it's a simpler
language?
Post by Rusi
Algol 68 project by IFIPS resulted in Pascal
Algol and Pascal are contemporaries, but Pascal was expressly designed
as a pedagogical language. That it succeeded in academia should be no
surprise, other than that it achieved Wirth's goals.
Post by Rusi
Ada project by the US DoD resulted in C
Ada was developed concurrently with C, but C was in widespread use long
before the DoD idiotically standardized on Ada in ... 1991. By that
time C had escaped Bell Labs and been ratified by ANSI, not to mention
had been used to write at least 4 operating systems. Ada's impact on C
was nil.
Post by Rusi
The OS/2 project by IBM and Microsoft resulted in Windows
Because Windows was simpler? Debatable, to say the least. There's a
lot of industrial intrigue in that story, and marketing savvy.

And technical merit. What IBM really missed was exploiting protected
mode while supporting real-mode DOS applications. Window's was "good
enough" for most people: it ran faster and had 10x the application that
OS/2 ever had. Windows NT was a game changer: protected memory and full
multitasking for a couple thousand bucks. It cost 1/10 of the
competition, and had at least 10x the application suite. OS/2 had
neither the technical competency nor the application support.

--jkl
Drew Adams
2018-11-16 17:15:08 UTC
Permalink
Post by James K. Lowden
Post by Rusi
The PL/I project by IBM and SHARE resulted in
Fortran and COBOL
PL/1 post-dates Cobol by at least 7 years. By the time PL/1 was
available, Cobol was already commercially successful. What use did the
Cobol programmer have for PL/1? And what evidence that it's a simpler
language?
And Fortran certainly came years before "the PL/I project".

https://en.wikipedia.org/wiki/PL/I#Early_history
James K. Lowden
2018-11-16 16:40:02 UTC
Permalink
On Thu, 15 Nov 2018 18:48:53 -0800 (PST)
Post by Rusi
http://blog.languager.org/2014/04/unicoded-python.html
I think you're overlooking the paucity of keyboard characters. I doubt
many programmers want to learn an input system to allow them to
represent, say, u2208. Never mind *one* input system; you have to
explain how to enter that symbol under Windows, on a Macintosh, in X,
and in a VT100 emulator, if not some combination of those.

You're also overestimating the mathematical literacy of the programming
public, but that's a separate matter. :-(

--jkl
Rusi
2018-11-17 15:59:49 UTC
Permalink
Post by James K. Lowden
On Thu, 15 Nov 2018 18:48:53 -0800 (PST)
Post by Rusi
http://blog.languager.org/2014/04/unicoded-python.html
I think you're overlooking the paucity of keyboard characters. I doubt
many programmers want to learn an input system to allow them to
represent, say, u2208. Never mind *one* input system; you have to
explain how to enter that symbol under Windows, on a Macintosh, in X,
and in a VT100 emulator, if not some combination of those.
If you look at your keyboard I am ready to bet that
- in the middle row on the left side you have a key that looks like ‘A’
- when you type it you get a char that looks more like ‘a’
- and only with the SHIFT-A chord generates an ‘A’.
IOW You are already using a non-trivial input method.

We tend to say “I am using an ASCII keyboard”. In loose informal language this is ok
However technically there is no such thing as an ASCII keyboard. What we call an
ASCII keyboard is most likely us-104 ... something that does not have a one to
one relation with ASCII.

You can see this more clearly from the hardware angle:
What the keyboard sends to the computer when you type the ‘A’ key is a scan code
and has no relation whatever with A/a characters.

And once you see
1 You are in any case using an input method
2 Which is user-choosable at OS/X/emacs etc level in any modern system
it becomes natural to ask: Is the default best for me/my current usage?

At this point the real difficult questions start popping up:

To type αβςδεφγηιθκλμνοπχρστυvωξψζ I just typed abcdefgjijklmnopqrstuvwxyz
with the greek(-babel) input method in emacs.
This may be a reasonable choice if I were Homer(!)
But in the more likely case of being a typical mathematician who sprinkles greek on his writings without a clue about greek, this would be highly inconvenient. Tex input method would likely be better
So the real question is this: If Unicode has a 150,000 code points and a keyboard can be setup to input a few hundred (say) chars conveniently which should I assign for my convenience?

This is a real hard question…
The only answer I am sure of is a negative one — the default is almost certainly sub-optimal for almost everyone: On my keyboard I see two sets of digits, two sets of arrow keys, two sets of +-*/.
Two minus signs and no em,en dash! Seriously!
And above the digits I see !@#$%^&*()
I cant see why I would like to use any of these — other than !() — except for decades of ASCII overloading and misuse (perlish!) bad habits
And ignore all these beauties!
http://xahlee.info/comp/unicode_math_operators.html
James K. Lowden
2018-11-19 22:23:58 UTC
Permalink
On Sat, 17 Nov 2018 07:59:49 -0800 (PST)
Post by Rusi
So the real question is this: If Unicode has a 150,000 code points
and a keyboard can be setup to input a few hundred (say) chars
conveniently which should I assign for my convenience?
This is a real hard question?
Exactly my point.
Post by Rusi
IOW You are already using a non-trivial input method.
Actually, it is a trival input method. Nearly all keyboards have
symbol emblazoned on each key; exceptions are rare [1]. The user
expects each key to produce one of two characters associated with each
key. That, I would say, is about as trivial as it gets.

Since we're ostensibly talking about emacs, I'll point you to M-x.
Despite emacs' generous capacity to overload keys with meaning,
ultimate just the functions of the editor overwhelm the available
keys. Where the world are you going to put 150,000 code points when
nroff mode steals M-s from occur to center a line?

The moment you move from a 1:1 correspondence to key to character to
N:1, the possibilities do become endless. The "compose" key in X, Tex,
and troff are examples. But they are also daunting. Just as
alphabetic languages use letters to form words, such input systems use
keys to form characters. It's a new language.

I'm simply suggesting that for most programmers, the beauty of reading
a non-alphabetic programming language is not worth the hassle of
learning to type it. As evidence, I give you APL: every successor
dropped the exotic character set, despite being invented since the
advent of Unicode and bitmapped displays.

--jkl

[1] https://www.daskeyboard.com/daskeyboard-4-ultimate/
Stefan Monnier
2018-11-19 23:11:44 UTC
Permalink
Post by James K. Lowden
I'm simply suggesting that for most programmers, the beauty of reading
a non-alphabetic programming language is not worth the hassle of
learning to type it. As evidence, I give you APL: every successor
dropped the exotic character set, despite being invented since the
advent of Unicode and bitmapped displays.
FWIW, in the Agda language, it's very common to use non-ASCII characters
which are input (in agda-mode) via a variant of the TeX input method.
The reason this is tolerated is because those chars are already familiar
to most users because they're used on paper for the same purpose.


Stefan
Amin Bandali
2018-11-20 06:15:31 UTC
Permalink
Post by Stefan Monnier
FWIW, in the Agda language, it's very common to use non-ASCII characters
which are input (in agda-mode) via a variant of the TeX input method.
The reason this is tolerated is because those chars are already familiar
to most users because they're used on paper for the same purpose.
Same with Lean: lean-mode comes with lean-input which is based on
agda-input with minor changes, and it makes it /super/ convenient
to insert commonly used unicode characters: \a for α, \b for β,
a\1 for a₁, \and for ∧, \|- for ⊢, and hundreds more. I’ve
actually come to like lean-input so much that I’ve set it as my
default-input-method so I can toggle it with C-\ and easily type
unicode symbols whenever and wherever I want.

I’ve been experimenting with using lean-input along with the
unicode-math package (for {Lua,Xe}TeX) and it has drastically
improved my experience with writing and reading Org and TeX
documents. It’s possible to change the input prefix from
backslash to something else to avoid clashes when writing TeX¹.

Footnotes:
¹ https://git.sr.ht/~bandali/dotfiles/commit/e44b9b7eb100a3d5c1640b7df7d4c458f81998ab
Stefan Monnier
2018-11-21 15:05:25 UTC
Permalink
Post by Amin Bandali
Same with Lean: lean-mode comes with lean-input which is based on
agda-input with minor changes, and it makes it /super/ convenient
to insert commonly used unicode characters: \a for α, \b for β,
a\1 for a₁, \and for ∧, \|- for ⊢, and hundreds more. I’ve
actually come to like lean-input so much that I’ve set it as my
default-input-method so I can toggle it with C-\ and easily type
unicode symbols whenever and wherever I want.
Maybe we should add a "math" input method along the lines of those
Agda/Lean input methods. I currently use the TeX input method for such
purposes but it tends to be a bit more verbose than I like.
Post by Amin Bandali
It’s possible to change the input prefix from
backslash to something else to avoid clashes when writing TeX¹.
In my experience (using the TeX input method when writing LaTeX),
I think the main problem with the clash on \ is that when the LaTeX
command I write has a valid prefix in the input method, the input method
rewrites that prefix. If we could fix it so that "\b" inputs "β" but
"\beta" isn't rewritten to "βeta" then I might even be able to have \
play both roles without going bonkers.


Stefan
Amin Bandali
2018-11-23 03:41:16 UTC
Permalink
Post by Stefan Monnier
Maybe we should add a "math" input method along the lines of those
Agda/Lean input methods. I currently use the TeX input method for such
purposes but it tends to be a bit more verbose than I like.
A proper “math”/“logic” input method would be awesome. Also, I
too find the TeX input method very verbose and much prefer the
shorter and easier-to-remember aliases of the Lean/Agda input
methods.
Post by Stefan Monnier
In my experience (using the TeX input method when writing LaTeX),
I think the main problem with the clash on \ is that when the LaTeX
command I write has a valid prefix in the input method, the input method
rewrites that prefix. If we could fix it so that "\b" inputs "β" but
"\beta" isn't rewritten to "βeta" then I might even be able to have \
play both roles without going bonkers.
Indeed, I think fixing that would alleviate a major pain point
with the default \ prefix. I guess the user then wouldn’t have
to also escape the \ itself (by typing it twice) when wanting to
write actual TeX commands?

-amin
Rusi
2018-11-28 14:14:38 UTC
Permalink
Post by Amin Bandali
Post by Stefan Monnier
FWIW, in the Agda language, it's very common to use non-ASCII characters
which are input (in agda-mode) via a variant of the TeX input method.
The reason this is tolerated is because those chars are already familiar
to most users because they're used on paper for the same purpose.
Same with Lean: lean-mode comes with lean-input which is based on
agda-input with minor changes, and it makes it /super/ convenient
to insert commonly used unicode characters: \a for α, \b for β,
a\1 for a₁, \and for ∧, \|- for ⊢, and hundreds more. I’ve
actually come to like lean-input so much that I’ve set it as my
default-input-method so I can toggle it with C-\ and easily type
unicode symbols whenever and wherever I want.
Thanks for pointing out lean to me
[And not just because its spelt L∃∀N !]

Do you have a good comparison of the contenders lean, agda, idris isabelle(?) etc?
Rusi
2018-11-28 14:10:48 UTC
Permalink
Post by Stefan Monnier
Post by James K. Lowden
I'm simply suggesting that for most programmers, the beauty of reading
a non-alphabetic programming language is not worth the hassle of
learning to type it. As evidence, I give you APL: every successor
dropped the exotic character set, despite being invented since the
advent of Unicode and bitmapped displays.
FWIW, in the Agda language, it's very common to use non-ASCII characters
which are input (in agda-mode) via a variant of the TeX input method.
The reason this is tolerated is because those chars are already familiar
to most users because they're used on paper for the same purpose.
I did not want to bring in Agda since I think it botches up unicode input with
over enthusiasm [I dont know much Agda FWIW]

However the number of ways of doing unicode badly should be combinatorially larger
than the number of ways of doing it right

Heres python3 compared to elisp


ELISP> (setq flag "hi")
"hi"
ELISP> (setq flag "there")
"there"
ELISP> (list flag flag)
("hi" "there")

ELISP> (setq á "hi")
"hi"
ELISP> (setq á "there")
"there"
ELISP> (list á á)

Python
Post by Stefan Monnier
Post by James K. Lowden
flag = 1
flag = 2
(flag, flag)
(2, 2)
Post by Stefan Monnier
Post by James K. Lowden
á = 1
á = 2
(á, á)
(2, 2)

In my view python does it right(er) than elisp (Haskell is in elisp category)
where "right" is defined by :identifiers should identify



However when push comes to shove both python and elisp are equally bad
Post by Stefan Monnier
Post by James K. Lowden
Α = "hi"
A = "there"
(Α,A)
('hi', 'there')


ELISP> (setq Α "hi")
"hi"
ELISP> (setq A "there")
"there"
ELISP> (list Α A)
("hi" "there")

which brings me to…
Post by Stefan Monnier
On Sat, 17 Nov 2018 07:59:49 -0800 (PST)
Post by James K. Lowden
IOW You are already using a non-trivial input method.
Actually, it is a trival input method. Nearly all keyboards have
symbol emblazoned on each key; exceptions are rare [1]. The user
expects each key to produce one of two characters associated with each
key. That, I would say, is about as trivial as it gets.
Notice how anglo-centric above is??
If you find ‘A’ an ‘a’ as trivially the same
what do you say about ‘A’ and ‘Α’??

PS Just to be clear: I am no fan of liberalism multi-culturalism and all that
jazz; just pointing out that all modern programming languages are falling over
each other to be more virtuous
Even C seems to have something called extended identifiers¿?
Eli Zaretskii
2018-11-28 16:31:12 UTC
Permalink
Date: Wed, 28 Nov 2018 06:10:48 -0800 (PST)
ELISP> (setq flag "hi")
"hi"
ELISP> (setq flag "there")
"there"
ELISP> (list flag flag)
("hi" "there")
ELISP> (setq á "hi")
"hi"
ELISP> (setq á "there")
"there"
ELISP> (list á á)
Python
flag = 1
flag = 2
(flag, flag)
(2, 2)
á = 1
á = 2
(á, á)
(2, 2)
In my view python does it right(er) than elisp
That's debatable: the Unicode Standard says to act according to
canonical equivalence only in text, whereas the above are symbol
names. We do display them the same (if the font supports that), but
we aren't under any obligation to map them to the same symbols, IMO.
However when push comes to shove both python and elisp are equally bad
Α = "hi"
A = "there"
(Α,A)
('hi', 'there')
ELISP> (setq Α "hi")
"hi"
ELISP> (setq A "there")
"there"
ELISP> (list Α A)
("hi" "there")
Why bad? Those characters are not canonically equivalent. If you
want to go by compatibility equivalence, you will enter a slippery
slope, where, for example, Ⅰ and 1 will yield the same symbol or even
the same number. Is that what you (or we) really want? I'd be
surprised.
Yuri Khan
2018-11-28 18:15:41 UTC
Permalink
Post by Eli Zaretskii
Post by Rusi
(á, á)> > (2, 2)
In my view python does it right(er) than elisp
That's debatable: the Unicode Standard says to act according to
canonical equivalence only in text, whereas the above are symbol
names. We do display them the same (if the font supports that), but
we aren't under any obligation to map them to the same symbols, IMO.
Standard Annex 31 deals with identifiers in programming languages, and
recommends considering identifiers equivalent if they are the same
under Normalization Form C for case-sensitive languages (such as
Python and Elisp).

(It suggests using Normalization Form KC for case-insensitive
languages, although I do not see how compatibility decomposition is
similar to case folding.)
Post by Eli Zaretskii
Post by Rusi
ELISP> (list Α A)
("hi" "there")
Why bad? Those characters are not canonically equivalent.
They are not even compatibility equivalent. Homoglyphic, yes, but not
equivalent in any way.
Post by Eli Zaretskii
If you
want to go by compatibility equivalence, you will enter a slippery
slope, where, for example, Ⅰ and 1 will yield the same symbol or even
the same number.
No they won’t. Compatibility decomposition of U+2160 ROMAN NUMERAL ONE
is U+0073 LATIN CAPITAL LETTER I.
Eli Zaretskii
2018-11-28 18:57:50 UTC
Permalink
Date: Thu, 29 Nov 2018 01:15:41 +0700
Post by Eli Zaretskii
That's debatable: the Unicode Standard says to act according to
canonical equivalence only in text, whereas the above are symbol
names. We do display them the same (if the font supports that), but
we aren't under any obligation to map them to the same symbols, IMO.
Standard Annex 31 deals with identifiers in programming languages, and
recommends considering identifiers equivalent if they are the same
under Normalization Form C for case-sensitive languages (such as
Python and Elisp).
"Implementations that take normalization and case into account have
two choices: to treat variants as equivalent, or to disallow
variants."

So there's a choice.
(It suggests using Normalization Form KC for case-insensitive
languages, although I do not see how compatibility decomposition is
similar to case folding.)
Case-folding is considered a special case of character folding.
Post by Eli Zaretskii
Post by Rusi
ELISP> (list Α A)
("hi" "there")
Why bad? Those characters are not canonically equivalent.
They are not even compatibility equivalent.
I didn't say they were.
Post by Eli Zaretskii
If you
want to go by compatibility equivalence, you will enter a slippery
slope, where, for example, Ⅰ and 1 will yield the same symbol or even
the same number.
No they won’t. Compatibility decomposition of U+2160 ROMAN NUMERAL ONE
is U+0073 LATIN CAPITAL LETTER I.
Yes, a mistaken example, sorry. But the idea is clear, I hope. E.g.,
the compatibility decomposition of ⁵ is 5, and the compatibility
decomposition of ⑴, a single character, is (1), which is a list in
Emacs.

That way lies madness, IMO.
Yuri Khan
2018-11-28 19:08:29 UTC
Permalink
Post by Eli Zaretskii
the compatibility decomposition of ⁵ is 5, and the compatibility
decomposition of ⑴, a single character, is (1), which is a list in
Emacs.
That way lies madness, IMO.
FWIW, I agree, trying to apply too much decomposition is misguided.

(I was recently informed that web browsers allow the use of
compatibility characters in domain names, and compatibility-decompose
them before resolving, so U+338F “kilogram” becomes Kyrgyzstan and
milliliter maps to Mali. That *is* madness.)
Rusi
2018-11-29 05:37:15 UTC
Permalink
Post by Yuri Khan
(I was recently informed that web browsers allow the use of
compatibility characters in domain names, and compatibility-decompose
them before resolving, so U+338F “kilogram” becomes Kyrgyzstan and
milliliter maps to Mali.
I am being troublesome but (hopefully!) not malicious
Add some good ol badness as hot peppers to the cake
https://en.wikipedia.org/wiki/IDN_homograph_attack
Post by Yuri Khan
That *is* madness.)
Precisely my point
Post by Yuri Khan
From: Yuri Khan
Post by Eli Zaretskii
That's debatable: the Unicode Standard says to act according to
canonical equivalence only in text, whereas the above are symbol
names. We do display them the same (if the font supports that), but
we aren't under any obligation to map them to the same symbols, IMO.
Standard Annex 31 deals with identifiers in programming languages, and
recommends considering identifiers equivalent if they are the same
under Normalization Form C for case-sensitive languages (such as
Python and Elisp).
"Implementations that take normalization and case into account have
two choices: to treat variants as equivalent, or to disallow
variants."
So there's a choice.
And if you ask me, disallow is the reasonable default
Earlier I compared python3 and elisp — a nuanced comparison
A more basic comparison would be between python 2 and 3


$ cat simple.py
A = 1
A = 2
print("A, A, A==A : %s, %s, %s\n" % (A,A,A==A))


$ cat homoglyph.py
A = 1
А = 2
print("A, А, A==А : %s, %s, %s\n" % (A,А,A==А))

$ python2 simple.py
A, A, A==A : 2, 2, True

$ python3 simple.py
A, A, A==A : 2, 2, True

$ python3 homoglyph.py
A, А, A==А : 1, 2, False

$ python2 homoglyph.py
File "homoglyph.py", line 2
SyntaxError: Non-ASCII character '\xd0' in file homoglyph.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details


IMHO python 2 is doing the right thing not python3
As I am sure elisp would be doing if we could get a 25 year old version

We could sharpen the error if we liked:

$ cat homoglyphE.py
# -*- coding: utf-8 -*-
A = 1
А = 2
print("A, А, A==А : %s, %s, %s\n" % (A,А,A==А))



$ python2 homoglyphE.py
File "homoglyphE.py", line 3
А = 2
^
SyntaxError: invalid syntax

Loading...