On Wed, Aug 28, 2024 at 01:01:33PM -0700, David Elson wrote:
Hello. I have been using emacs for ... a while.
For questions, I have often browsed and browsed (i.e. googled) and ... and
usually find a good explanation. But sometimes I don't find an answer, even
when it is staring right at me.
My question:
To emulate something akin to the PL1/C/C++ arrow notation, I have used:
*(defun -> (object method &rest args) ...)*
and it works.
*Is this valid elisp/lisp?*
It is. From the elisp documentation:
-- Macro: defun name args [doc] [declare] [interactive] body...
‘defun’ is the usual way to define new Lisp functions. It defines
the symbol NAME as a function with argument list ARGS ...
... so NAME is a symbol. Again, from the doc:
A symbol name can contain any characters whatever. Most symbol names
are written with letters, digits, and the punctuation characters
‘-+=*/’. Such names require no special punctuation; the characters of
the name suffice as long as the name does not look like a number. (If
it does, write a ‘\’ at the beginning of the name to force
interpretation as a symbol.) The characters ‘_~!@$%^&:<>{}?’ are less
often used but also require no special punctuation. Any other
characters may be included in a symbol’s name by escaping them with a
backslash.
So "->" is not only a legal symbol name, but also one that doesn't need
special escaping to be seen as such. So go wild :)
Actually, Emacs Lisp comes with one function named "-" and another named
">".
That said, this doesn't mean that other people will find your code readable
or enjoyable. It's on you to find that out :-)
If it works only coincidentally, then it might break in the future, when a
pressing emacs issue is resolved in a manner that requires plugging this
"loophole".
If it is formally valid, where does it document the level of flexibility
that allows this syntax?
The Emacs Lisp documentation should be your go-to place for such questions.
Cheers