Gnus development mailing list
 help / color / mirror / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: ding@gnus.org
Subject: Re: Backquotes and commas and ",@"
Date: Sat, 10 Dec 2011 05:39:20 -0500	[thread overview]
Message-ID: <87ehwcn21z.fsf@lifelogs.com> (raw)
In-Reply-To: <87sjkskfsg.fsf_-_@dod.no>

On Sat, 10 Dec 2011 09:10:55 +0100 Steinar Bang <sb@dod.no> wrote: 

SB> So, what's still unclear, is:
SB>  1. Why backquote (or for that matter: "why quote?") the body of a
SB>     defun?  What does that mean?
#+begin_src emacs-lisp
  (defun gnus-sync-lesync-pre-save-group-entry (url nentry &rest passed-props)
    (let* ((loc "gnus-sync-lesync-save-group-entry")
	   (k (car nentry))
	   (revision (gnus-sync-lesync-get-prop 'rev k))
	   (sname gnus-sync-lesync-name)
	   (topic (gnus-group-topic k))
	   (topic-offset (gnus-sync-topic-group-position k topic))
	   (sources (gnus-sync-lesync-get-prop 'source k)))
      ;; set the revision so we don't have a conflict
      `(,@(when revision
      ...
#+end_src

The function returns a list.  It was more convenient to build the list
all at once, with interpolation, than imperatively with push/pop or
cons.

SB>  2. What does ",@" mean?  "Splice the result of the evaluation into
SB>     the list"...?  Ah... I think I actually understand now.  Looking
SB>     at the elisp manual examples for ",@", I see that it means that if
SB>     the result of the comma-evaluation is a list, the elements are
SB>     added as element of the list, not as a single element that is a
SB>     list.

,@ says "whatever list follows, splice it in."  If the list is empty,
nothing happens; it's convenient when you want some content to appear
only if it's not nil.  So for example

#+begin_src emacs-lisp
      ,@(if topic (list (cons 'topic topic)) nil)
#+end_src

will result in an alist member like '(topic "xyz") if the `topic'
variable was defined, and nothing will be inserted otherwise.

SB> This means that the gnus-sync-lesync-pre-save-group-entry function
SB> returns a list.  And that list, is:
SB>  - If there is a revision, start the list with the symbol '_rev
SB>    followed by the revision
SB>  - Then the list will have an element that is a two element list,
SB>    consisting of the symbol '_id and the first element of the nentry
SB>    argument to the function (I don't understand why you have to have
SB>    the "." there, though...?)
SB>  - Then passed props are spliced in (what happens if there is no
SB>    passed-props argument sent to the function?  It's optional...?)
SB>  - Then an element that is a list starting with "source" (whatever
SB>    that is), followed by the result of evaluating the "if"
SB>  - Then an element that is a two element list starting with 'level and
SB>    with a number(?) as the second element
SB>  - Then splice in the elements resulting from evaluating two "if"s
SB>    relating to topics
SB>  - Then an element that is a list containing the read marks
SB>  - Then an element that is a list containing other marks, and this is
SB>    the one that broke down for me, because it got a conflict marker
SB>    instead of the other marks

SB> And I'm guessing this list is a translation of JSON into lisp lists...

It's prep work for the actual save to JSON, converting arbitrary group
data (especially marks) into a more neutral format that json.el can
handle.

Ted






  parent reply	other threads:[~2011-12-10 10:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23 19:55 gnus-sync-save fails with "wrong-type-argument number-or-marker-p" Steinar Bang
2011-11-23 20:27 ` Steinar Bang
2011-12-06 21:17   ` Steinar Bang
2011-12-08 14:50     ` Ted Zlatanov
2011-12-08 19:07       ` Steinar Bang
2011-12-10  7:11         ` Steinar Bang
2011-12-10  7:29           ` Steinar Bang
2011-12-10  8:10             ` Backquotes and commas and ",@" (Was: gnus-sync-save fails with "wrong-type-argument number-or-marker-p") Steinar Bang
2011-12-10  9:04               ` Backquotes and commas and ",@" Andreas Schwab
2011-12-10  9:52                 ` Steinar Bang
2011-12-10 10:39               ` Ted Zlatanov [this message]
2011-12-10 11:07         ` gnus-sync-save fails with "wrong-type-argument number-or-marker-p" Ted Zlatanov
2011-12-10 14:19           ` Steinar Bang
2011-12-10 14:45             ` Steinar Bang
2011-12-10 14:49               ` Steinar Bang

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=87ehwcn21z.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=ding@gnus.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 NNTP newsgroup(s).