From: Richard Lawrence <rwl@recursewithless.net>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-devel@gnu.org
Subject: Re: Upstreaming org-element-ast (was: Improving Emacs' iCalendar support)
Date: Sun, 05 Jan 2025 10:52:38 +0100 [thread overview]
Message-ID: <874j2d8u55.fsf@recursewithless.net> (raw)
In-Reply-To: <8734i1q8p1.fsf@localhost>
Ihor Radchenko <yantar92@posteo.net> writes:
> Richard Lawrence <rwl@recursewithless.net> writes:
>
>> In any case, the issue with passing nil as the &rest argument is what
>> causes most of the tests to fail. This remains so even once I change the
>> call to use (apply #'org-element-create ...) as you suggested. This *is*
>> documented in the Elisp manual, and I guess it makes sense, but I still
>> find it somewhat unintuitive to reason about.
>
> May you please give an example illustrating the issue? I am not sure if
> I understand it fully.
OK, revisiting this after a few days...I'm not 100% sure I understand
it either.
Here is what I see: if I define ical:make-ast-node like
(defun ical:make-ast-node (type &optional props &rest children)
;; ...
(apply #'org-element-create type full-props children))
which is what I was doing in the hope that I could eventually just use
defalias, most of my parser tests fail with "X may not contain `nil'"
errors as I showed in a previous message. If instead I change the
definition to:
(defun ical:make-ast-node (type props &optional children)
;; ...
(apply #'org-element-create type full-props children))
which better reflects the usage pattern I need, then all the tests pass again.
The reason is that, with the former definition, children will be bound to
`(nil)' in the call to org-element-create, while in the latter it will
be bound to `nil'. The root of the problem is that
(org-element-create 'foo (list ...))
(org-element-create 'foo (list ...) nil)
are not equivalent; in particular
(org-element-contents (org-element-create 'foo (list ...))) ; => nil
(org-element-contents (org-element-create 'foo (list ...) nil)) ; => (nil)
This is the documented behavior of passing nil for a &rest argument (see
info node `(elisp)Argument list': "Note that exactly five arguments with
an explicit ‘nil’ argument provided for ‘e’ will cause that ‘nil’
argument to be passed as a list with one element, ‘(nil)’, as with any
other single value for ‘e’"). So it's not a problem per se.
But this interface to org-element-contents is not a good match for the
way my iCalendar parser works: a list of child nodes is always built up
*before* calling ical:make-ast-node/org-element-create. Sometimes this
list is empty, and sometimes it isn't, but it is always a list, and I
always have a variable bound to this list which I want to provide as an
argument to the constructor. I imagine other parsers often work
similarly. Thus, it would be nice to have an interface where children is
not a &rest argument, so that calling it like
(org-element-create* 'foo (list ...) the-child-nodes)
will work even if the-child-nodes is nil, rather than having to either
(a) say
(if the-child-nodes
(org-element-create* 'foo (list ...) the-child-nodes)
(org-element-create* 'foo (list ...)))
or (b) write a wrapper for org-element-create with a different argument
list definition, as I have now.
Is that clearer?
Best,
Richard
next prev parent reply other threads:[~2025-01-05 9:52 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 9:01 Improving Emacs' iCalendar support Richard Lawrence
2024-10-18 9:24 ` Eli Zaretskii
2024-10-19 8:22 ` Richard Lawrence
2024-10-19 10:11 ` Eli Zaretskii
2024-10-20 5:08 ` Richard Lawrence
2024-10-20 5:21 ` Eli Zaretskii
2024-10-18 12:58 ` Sebastián Monía
2024-10-19 8:28 ` Richard Lawrence
2024-10-19 5:44 ` Adam Porter
2024-10-19 8:39 ` Richard Lawrence
2024-10-20 3:09 ` Adam Porter
2024-10-22 18:40 ` Ihor Radchenko
2024-10-23 7:29 ` Björn Bidar
[not found] ` <87plnr6zvk.fsf@>
2024-10-23 8:09 ` Ihor Radchenko
2024-10-23 9:05 ` Richard Lawrence
2024-10-23 10:03 ` Björn Bidar
2024-10-23 9:01 ` Richard Lawrence
2024-10-23 20:24 ` Ferdinand Pieper
2024-10-24 14:52 ` Richard Lawrence
2024-10-24 17:45 ` Ihor Radchenko
2024-10-25 12:53 ` Richard Lawrence
2024-10-25 18:59 ` Ihor Radchenko
2024-10-21 6:10 ` Björn Bidar
2024-10-21 6:22 ` Visuwesh
2024-10-23 9:15 ` Richard Lawrence
2024-10-23 9:45 ` Visuwesh
[not found] ` <87wmi29eaf.fsf@>
2024-10-26 17:49 ` Ihor Radchenko
2024-10-28 10:44 ` Björn Bidar
[not found] ` <87r080tslf.fsf@>
2024-10-28 19:09 ` Ihor Radchenko
2024-11-23 8:44 ` Richard Lawrence
2024-11-24 9:50 ` Eli Zaretskii
2024-11-24 10:21 ` Ihor Radchenko
2024-11-24 10:41 ` Eli Zaretskii
2024-11-24 10:58 ` Ihor Radchenko
2024-11-24 11:08 ` Eli Zaretskii
2024-11-24 11:21 ` Upstreaming org-element-ast (was: Improving Emacs' iCalendar support) Ihor Radchenko
2024-11-24 12:55 ` Eli Zaretskii
2024-12-25 11:31 ` Ihor Radchenko
2024-12-29 20:19 ` bug#74994: " Richard Lawrence
2024-12-29 20:19 ` Richard Lawrence
2024-12-29 20:53 ` bug#74994: " Richard Lawrence
2024-12-29 20:53 ` Richard Lawrence
2024-12-30 17:18 ` bug#74994: " Ihor Radchenko
2024-12-30 17:18 ` Ihor Radchenko
2024-12-30 17:16 ` bug#74994: " Ihor Radchenko
2024-12-31 7:55 ` Richard Lawrence
2025-01-01 9:29 ` Ihor Radchenko
2025-01-01 12:38 ` Richard Lawrence
2025-01-02 18:03 ` Ihor Radchenko
2025-01-02 20:01 ` Richard Lawrence
2025-01-02 20:09 ` Ihor Radchenko
2025-01-05 9:52 ` Richard Lawrence [this message]
2025-01-05 13:30 ` Ihor Radchenko
2025-01-01 13:01 ` Richard Lawrence
2025-01-05 8:33 ` Ihor Radchenko
2024-11-25 9:09 ` Improving Emacs' iCalendar support Richard Lawrence
2024-11-25 12:42 ` Eli Zaretskii
2024-11-25 13:03 ` Rudolf Schlatte
2024-11-25 13:36 ` Eli Zaretskii
2024-11-25 17:14 ` Richard Lawrence
2024-12-20 13:21 ` Richard Lawrence
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=874j2d8u55.fsf@recursewithless.net \
--to=rwl@recursewithless.net \
--cc=emacs-devel@gnu.org \
--cc=yantar92@posteo.net \
/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.