From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: David Elson Newsgroups: gmane.emacs.help Subject: Re: syntax question for defun Date: Thu, 29 Aug 2024 09:45:59 -0700 Message-ID: <7c5c55a8-59bc-4d2e-9fee-bd924a323470@greatalpha.com> References: <6a7b894c-8c00-482e-b75c-ce87c0eb2b9c@greatalpha.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10169"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: help-gnu-emacs@gnu.org To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 29 18:46:54 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjiIO-0002L0-U1 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 29 Aug 2024 18:46:52 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjiHp-0002s5-Pj; Thu, 29 Aug 2024 12:46:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjiHk-0002rZ-1K for help-gnu-emacs@gnu.org; Thu, 29 Aug 2024 12:46:12 -0400 Original-Received: from smtprelay0016.hostedemail.com ([216.40.44.16] helo=relay.hostedemail.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjiHd-0000Dx-9j for help-gnu-emacs@gnu.org; Thu, 29 Aug 2024 12:46:10 -0400 Original-Received: from omf18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 84DE0C055C; Thu, 29 Aug 2024 16:46:02 +0000 (UTC) Original-Received: from [HIDDEN] (Authenticated sender: delson@greatalpha.com) by omf18.hostedemail.com (Postfix) with ESMTPA id 8BA5834; Thu, 29 Aug 2024 16:46:00 +0000 (UTC) Content-Language: en-US In-Reply-To: X-Rspamd-Queue-Id: 8BA5834 X-Rspamd-Server: rspamout06 X-Stat-Signature: 9bkiyasqetkkfb1mabmze3udtuszf4qn X-Session-Marker: 64656C736F6E406772656174616C7068612E636F6D X-Session-ID: U2FsdGVkX1+gNNEdcFPz5pb5WTetO2Qo6B7xEG3gc8Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greatalpha.com; h=content-type:message-id:date:mime-version:subject:to:cc:references:from:in-reply-to; s=he; bh=WOG65Yib0SoPLJ45yF65G18mgDTgoMoE5iBE7ww7MlM=; b=KCzFbWJzw7C5diDQrGUb7S9h1ZKoYvRtyP/6EiqS5l17faATfw9YnxZeOMOXmm21MOvzy4Z0QP82FhNwMuvxBQZVmDt3UkF9WXDIFBTP42G7RagL1xaubIDzIDt16eZd7CtDdIJI+SFQl2NueLlyPwEMRcxr5EoSV8Dv2VAPEA0= X-HE-Tag: 1724949960-127858 X-HE-Meta: U2FsdGVkX1/djy1EOdTU5c8gayS2/hxOK0sHT9jnS3pRfPPujNJe3cHSF/sAuObja8lkjmizwym3gz/FztYqwDkdKB1mJfqTe4yklJ7whXy25A/UH/aALT40QEbJ/0M4p+ls+xoHsCYdD3LFjmK0+yyy60vVouBXAsp7BH5tguH9akpSBpq9CLobbQ8qnIvuGcqdhoh7c7xcILIYR66ggYoSRcFfsPdEO+jAZi348truGAdmMuiooZYaYivLWD504d3dW7N1WaRnc6AfVBdk7WOJH2+8qzGviYjhdyPNw4X81L7KVmt0I69vz8T3GZBnVYXlSDI7I5uxSPqkDROWmDZ110XC+XCLDZyiIZzQtHIdWHxtOIde/PIrW4a6w9qp2zSJGEmXHHmsxG2cmzlHjF/QpVXXGNtSkXYeGYSv/GdaiZv4JpCgIUlfFYijdcz2G54XBjeXUWpCqnQS1IBTQg== Received-SPF: pass client-ip=216.40.44.16; envelope-from=delson@greatalpha.com; helo=relay.hostedemail.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147854 Archived-At: 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