all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Heime <heimeborgia@protonmail.com>
Cc: Pierre Rouleau <prouleau001@gmail.com>,
	Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: RE: [External] : Re: Passing result of macroexpand-all as argument to a function
Date: Wed, 9 Aug 2023 04:14:34 +0000	[thread overview]
Message-ID: <SJ0PR10MB54888DD37635EDB488F591E8F312A@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <8jYTST4ZkiHwzpQf6qnWQ9vjFoSbMlhTJmH2ReO4KSw0O0PHGXhtGaGvsT6fugo3G-ibKDxfXErDu5mRKvFdKGhGitKSXiHKAB7pomMnt8w=@protonmail.com>

> I want to pass other variables to my function, example a a buffer name
> like so
> (myfunc ` ,(macroexpand-all something arg) bfname)

No problem. The backquote+comma apply only to the
expression that immediately follows.

The call to myfunc evaluates all of its arguments.

The backquote+comma evaluates
(macroexpand-all something arg) and quotes the result.
That quoted value gets passed as the argument.

That arg gets evaluated normally, yielding the result
of evaluating (macroexpand-all something arg).

The second arg, variable bfname, is evaluated as an
arg, as usual.

E.g., if (macroexpand-all something arg) expands to
the variable foobar, then 'foobar is passed to
myfunc, along with bfname.  So the symbol foobar is
passed as the first arg, and the value of variable
bfname is passed as the second arg.

If (macroexpand-all something arg) instead expands
to (foobar toto) then '(foobar toto) is passed to
myfunc.  Since the arg is evaluated for the myfunc
function call, the list (foobar toto) is passed:
the result of evaluating '(foobar toto), aka
(quote (foobar toto)).

> What I am worried about is this.  Would myfunc get confused when the code
> of macroexpand-all ends and when bfname starts ?

No.  The result of evaluating (macroexpand-all...)
is a Lisp object.  That's quoted and passed to
myfunc.  The result of evaluating that quoted
result of macroexpansion is that result (unquoted).
The result of evaluating variable bfname is a
another Lisp object.

> If I understand correctly, just calling would get the result from
> (macroexpand-all something arg) but then evaluate it because the macro
> code changes in context when used as an argument to a function.

Dunno what you mean by that.

> (myfunc (macroexpand-all something arg) bfname)

That would pass the result of macroexpansion as
the first arg to myfunc.  Evaluating the myfunc
function call would _evaluate_ that arg.  You
apparently don't want that, so you quote it.
To do that, use `,(macroexpand-all something arg).

I said, above, "The backquote+comma apply only
to the expression that immediately follows."
A better way to look at it is that the ` really
envelopes the sexp that follows it.  Really, what
happens is that the `... is shorthand for
(backquote ...).

The symbol whose name is just a backquote char
(`) is an alias for the macro named "backquote":

(defalias '\` (symbol-function 'backquote))

Here you see that the sexp that follows the ` is
really just an arg passed to macro backquote:

(macroexpand (backquote ',(setq foo 42))) ; '42
(macroexpand (backquote '(setq foo 42)))  ; '(setq foo 42)

(macroexpand `',(setq foo 42)) ; '42
(macroexpand `'(setq foo 42))  ; '(setq foo 42)

C-h f backquote, or `C-h f `, to learn more.

> I just say things how they are.  If I do not understand
> and the manual is of no help (to me of course), no
> amount of abuse from anyone will convince my understanding.

No one is abusing you.  Soon maybe you will help
others with Lisp.  Everyone can learn; everyone
can teach.  Everyone needs help.  Everyone can
appreciate help, and show it by helping others.

Someone who only asks for help but doesn't help
will sooner or later lack others willing to help.
Changing names only works locally & temporarily.

  parent reply	other threads:[~2023-08-09  4:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09  0:22 Passing result of macroexpand-all as argument to a function Heime
2023-08-09  1:37 ` Pierre Rouleau
2023-08-09  2:04   ` Heime
2023-08-09  2:26     ` Corwin Brust
2023-08-09  2:40       ` Heime
2023-08-09  2:27     ` [External] : " Drew Adams
2023-08-09  2:53       ` Heime
2023-08-09  4:02         ` Pierre Rouleau
2023-08-09  4:14         ` Drew Adams [this message]
2023-08-09  3:37       ` Michael Heerdegen
2023-08-09  4:13         ` Heime
2023-08-09  4:36           ` Michael Heerdegen
2023-08-09  4:54             ` Heime
2023-08-09 15:21               ` Drew Adams
2023-08-09  4:28         ` Drew Adams
2023-08-09  3:39     ` Michael Heerdegen
2023-08-09  5:06       ` Heime
2023-08-09 15:27         ` [External] : " Drew Adams
2023-08-09 20:34           ` Heime
2023-08-09 21:24             ` Drew Adams
2023-08-09 21:32               ` Heime

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=SJ0PR10MB54888DD37635EDB488F591E8F312A@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=prouleau001@gmail.com \
    /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.