* syntax question for defun @ 2024-08-28 20:01 David Elson 2024-08-29 4:57 ` tomas 0 siblings, 1 reply; 5+ messages in thread From: David Elson @ 2024-08-28 20:01 UTC (permalink / raw) To: help-gnu-emacs 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?* 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? If it is not formally valid, then why does it work coincidentally? I'd like to enhance/use this code, but I hesitate due to this question. Thanks in advance? -David ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax question for defun 2024-08-28 20:01 syntax question for defun David Elson @ 2024-08-29 4:57 ` tomas 2024-08-29 16:45 ` David Elson 0 siblings, 1 reply; 5+ messages in thread From: tomas @ 2024-08-29 4:57 UTC (permalink / raw) To: David Elson; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 2118 bytes --] 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 -- t [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax question for defun 2024-08-29 4:57 ` tomas @ 2024-08-29 16:45 ` David Elson 2024-08-29 18:29 ` tomas 2024-08-29 19:28 ` Stefan Monnier via Users list for the GNU Emacs text editor 0 siblings, 2 replies; 5+ messages in thread From: David Elson @ 2024-08-29 16:45 UTC (permalink / raw) To: tomas; +Cc: help-gnu-emacs Many *many* thanks tomas !!! The information you have provided not only answers my basic question (I was able to find the sections by googling effectively disambiguating strings from your fine reply), but gives me some good insight into more properly reading the elisp docs. Pending a look at elisp lexical analysis code (would be interesting), I'll count on algorithmic "greediness" to disambiguate '->' from '-' (:-), and a new battery in my keyboard to disambiguate it from '>' (:-). I try to write clear code, but sometimes ... always a good caution, though. Y'all be well. -DE PS Also, per your excellent reply, I will go (cautiously) wild with this (pun intended). PPS (please pardon the *skippable* after-the-fact context) As for readability, I try to keep the number of columns down, mainly due to the way I tend to split windows. Some elisp code from 2018, not (yet) intended for anyone (else). I'm sure there are many ways, per knowledgeable folks such as yourself, to improve the approach/style, and I'm all ears. This is just a snippet of what I was starting with: (require 'object) ... (defun new-filter-state-machine () (let* ( (fsm (new-object 'filter-state-machine)) ) (-> fsm 'add-attr 'state 0) (-> fsm 'add-attr 'exp-len -1) (-> fsm 'add-method 'reset (lambda (this) (-> this 'set-state 0) (-> this 'set-exp-len -1) t ) ) (-> fsm 'add-method 'process-string ... On 8/28/24 9:57 PM, tomas@tuxteam.de wrote: > 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax question for defun 2024-08-29 16:45 ` David Elson @ 2024-08-29 18:29 ` tomas 2024-08-29 19:28 ` Stefan Monnier via Users list for the GNU Emacs text editor 1 sibling, 0 replies; 5+ messages in thread From: tomas @ 2024-08-29 18:29 UTC (permalink / raw) To: David Elson; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 440 bytes --] On Thu, Aug 29, 2024 at 09:45:59AM -0700, David Elson wrote: > Many *many* thanks tomas !!! > > The information you have provided not only answers my basic question (I was > able to find the sections by googling effectively disambiguating strings > from your fine reply), but gives me some good insight into more properly > reading the elisp docs. Glad it helped. I see you are enjoying -- thus doubly glad :-) Cheers -- t [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax question for defun 2024-08-29 16:45 ` David Elson 2024-08-29 18:29 ` tomas @ 2024-08-29 19:28 ` Stefan Monnier via Users list for the GNU Emacs text editor 1 sibling, 0 replies; 5+ messages in thread From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-08-29 19:28 UTC (permalink / raw) To: help-gnu-emacs > Some elisp code from 2018, not (yet) intended for anyone (else). I'm sure > there are many ways, per knowledgeable folks such as yourself, to improve > the approach/style, and I'm all ears. This is just a snippet of what I was > starting with: You might enjoy Eoops: an object-oriented programming system for Emacs-Lisp Houser, Chris and Kalter, Scott D. (1992) https://dl.acm.org/doi/10.1145/147135.147248 https://www.emacswiki.org/emacs/EmacsObjectOrientedProgrammingSystem - Stefan ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-29 19:28 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-08-28 20:01 syntax question for defun David Elson 2024-08-29 4:57 ` tomas 2024-08-29 16:45 ` David Elson 2024-08-29 18:29 ` tomas 2024-08-29 19:28 ` Stefan Monnier via Users list for the GNU Emacs text editor
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.