From: <tomas@tuxteam.de>
To: David Elson <delson@greatalpha.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: syntax question for defun
Date: Thu, 29 Aug 2024 06:57:48 +0200 [thread overview]
Message-ID: <Zs//zMd5c5UPq3JP@tuxteam.de> (raw)
In-Reply-To: <6a7b894c-8c00-482e-b75c-ce87c0eb2b9c@greatalpha.com>
[-- 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 --]
next prev parent reply other threads:[~2024-08-29 4:57 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 [this message]
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
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zs//zMd5c5UPq3JP@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=delson@greatalpha.com \
--cc=help-gnu-emacs@gnu.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).