all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Elson <delson@greatalpha.com>
To: tomas@tuxteam.de
Cc: help-gnu-emacs@gnu.org
Subject: Re: syntax question for defun
Date: Thu, 29 Aug 2024 09:45:59 -0700	[thread overview]
Message-ID: <7c5c55a8-59bc-4d2e-9fee-bd924a323470@greatalpha.com> (raw)
In-Reply-To: <Zs//zMd5c5UPq3JP@tuxteam.de>

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


  reply	other threads:[~2024-08-29 16:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-28 20:01 syntax question for defun David Elson
2024-08-29  4:57 ` tomas
2024-08-29 16:45   ` David Elson [this message]
2024-08-29 18:29     ` tomas
2024-08-29 19:28     ` Stefan Monnier via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c5c55a8-59bc-4d2e-9fee-bd924a323470@greatalpha.com \
    --to=delson@greatalpha.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=tomas@tuxteam.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.