unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Passing result of macroexpand-all as argument to a function
@ 2023-08-09  0:22 Heime
  2023-08-09  1:37 ` Pierre Rouleau
  0 siblings, 1 reply; 21+ messages in thread
From: Heime @ 2023-08-09  0:22 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

If I want to pass the result of a macro without final evaluation as argument
to a function, what kind of structure will it be ?

I would be using

(macroexpand-all (this-macro arg))

which I would pass as argument to a function.






^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Passing result of macroexpand-all as argument to a function
  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
  0 siblings, 1 reply; 21+ messages in thread
From: Pierre Rouleau @ 2023-08-09  1:37 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Tue, Aug 8, 2023 at 8:22 PM Heime <heimeborgia@protonmail.com> wrote:

> If I want to pass the result of a macro without final evaluation as
> argument
> to a function, what kind of structure will it be ?
>
> I would be using
>
> (macroexpand-all (this-macro arg))
>
> which I would pass as argument to a function.
>
> 1- What is the problem that you are trying to solve?

2- If you want to pass something to a function and you want that something
not evaluated, then: quote it.  The function can later evaluate it if it
needs to extract the result of the expression, or it can print it using a
string formatting function.

3- If #2 is not clear, reading a LISP tutorial will help.   Investing time
reading on LISP and Emacs Lisp will help a lot.




-- 
/Pierre


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  1:37 ` Pierre Rouleau
@ 2023-08-09  2:04   ` Heime
  2023-08-09  2:26     ` Corwin Brust
                       ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Heime @ 2023-08-09  2:04 UTC (permalink / raw)
  To: Pierre Rouleau; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, August 9th, 2023 at 1:37 PM, Pierre Rouleau <prouleau001@gmail.com> wrote:


> On Tue, Aug 8, 2023 at 8:22 PM Heime heimeborgia@protonmail.com wrote:
> 
> > If I want to pass the result of a macro without final evaluation as
> > argument
> > to a function, what kind of structure will it be ?
> > 
> > I would be using
> > 
> > (macroexpand-all (this-macro arg))
> > 
> > which I would pass as argument to a function.
> > 
> > 1- What is the problem that you are trying to solve?
> 
> 
> 2- If you want to pass something to a function and you want that something
> not evaluated, then: quote it. The function can later evaluate it if it
> needs to extract the result of the expression, or it can print it using a
> string formatting function.
> 
> 3- If #2 is not clear, reading a LISP tutorial will help. Investing time
> reading on LISP and Emacs Lisp will help a lot.
 
I am going to pass 

(myfunc (macroexpand-all something arg) bfname)

How would I define myfunc ?

Will (macroexpand-all something arg) be in a form of a list (list of names
and arguments) or what ?
 
 
> --
> /Pierre



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Passing result of macroexpand-all as argument to a function
  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  3:39     ` Michael Heerdegen
  2 siblings, 1 reply; 21+ messages in thread
From: Corwin Brust @ 2023-08-09  2:26 UTC (permalink / raw)
  To: Heime; +Cc: Pierre Rouleau,
	Heime via Users list for the GNU Emacs text editor

On Tue, Aug 8, 2023 at 9:04 PM Heime <heimeborgia@protonmail.com> wrote:
>
> On Wednesday, August 9th, 2023 at 1:37 PM, Pierre Rouleau <prouleau001@gmail.com> wrote:
>
> > On Tue, Aug 8, 2023 at 8:22 PM Heime heimeborgia@protonmail.com wrote:
> >
> > 3- If #2 is not clear, reading a LISP tutorial will help. Investing time
> > reading on LISP and Emacs Lisp will help a lot.
>
> I am going to pass

What does "I am going to pass" mean, please?

I hope that it does not mean "I do not want to read the manual".  (Or
were you saying that you do not want to explain your problem, or
perhaps you object to quoting lisp forms to pass them around?)

I ask because, in my view, it is not acting kindly toward those who
read the list and attempt to help people, that you would refuse to
read the documentation.  In fact, it initially strikes me as rather
rude to depend only on others to personally explain solutions (to
problems that you do not define).  Especially so when I consider you
are depending on the rest of us to read the documentation (source,
this list, etc), in order to know something you don't.  I hope this
helps to make clear why I found your "I am going to pass" remark so
exceptional as to comment on it, choosing in this case to completely
ignore the context of whatever it is that you might want to know.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  2:04   ` Heime
  2023-08-09  2:26     ` Corwin Brust
@ 2023-08-09  2:27     ` Drew Adams
  2023-08-09  2:53       ` Heime
  2023-08-09  3:37       ` Michael Heerdegen
  2023-08-09  3:39     ` Michael Heerdegen
  2 siblings, 2 replies; 21+ messages in thread
From: Drew Adams @ 2023-08-09  2:27 UTC (permalink / raw)
  To: Heime, Pierre Rouleau; +Cc: Heime via Users list for the GNU Emacs text editor

> > > 1- What is the problem that you are trying to solve?
> >
> > 2- If you want to pass something to a function and you want that
> something
> > not evaluated, then: quote it. The function can later evaluate it if it
> > needs to extract the result of the expression, or it can print it using
> a
> > string formatting function.
> >
> > 3- If #2 is not clear, reading a LISP tutorial will help. Investing time
> > reading on LISP and Emacs Lisp will help a lot.
> 
> I am going to pass
> (myfunc (macroexpand-all something arg) bfname)
> 
> How would I define myfunc ?
> 
> Will (macroexpand-all something arg) be in a form of a list (list of names
> and arguments) or what ?

As several have said, a Lisp macro takes a list sexp that has a symbol car, that is, something that looks like a function call: (foo...), and it returns a Lisp form - pretty much any kind of Lisp object you like: a string, a symbol, a list, a vector, a character or other number.

`macroexpand-all` just expands the macro calls at all levels of its FORM argument: the topmost sexp and any sexps inside it - all the way down.

You've already been told that if you want to pass a Lisp object to a function without it being evaluated then quote it.

Since you want `macroexpand-all' to first expand your `something' form, you want to quote it after evaluating the `macroexpand-all' call.  How to do that is the among the FAQiest FAQs:

https://emacs.stackexchange.com/q/7481

IOW, (myfunc `,(macroexpand-all something arg))

As many have suggested to you ... the Elisp Intro manual is your friend, as is the Elisp manual.  It has a wealth of clear explanation and unlimited patience.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  2:26     ` Corwin Brust
@ 2023-08-09  2:40       ` Heime
  0 siblings, 0 replies; 21+ messages in thread
From: Heime @ 2023-08-09  2:40 UTC (permalink / raw)
  To: Corwin Brust
  Cc: Pierre Rouleau,
	Heime via Users list for the GNU Emacs text editor

------- Original Message -------
On Wednesday, August 9th, 2023 at 2:26 PM, Corwin Brust <corwin@bru.st> wrote:


> On Tue, Aug 8, 2023 at 9:04 PM Heime heimeborgia@protonmail.com wrote:
> 
> > On Wednesday, August 9th, 2023 at 1:37 PM, Pierre Rouleau prouleau001@gmail.com wrote:
> > 
> > > On Tue, Aug 8, 2023 at 8:22 PM Heime heimeborgia@protonmail.com wrote:
> > > 
> > > 3- If #2 is not clear, reading a LISP tutorial will help. Investing time
> > > reading on LISP and Emacs Lisp will help a lot.
> > 
> > I am going to pass
> 
> 
> What does "I am going to pass" mean, please?
> 
> I hope that it does not mean "I do not want to read the manual". (Or
> were you saying that you do not want to explain your problem, or
> perhaps you object to quoting lisp forms to pass them around?)
> 
> I ask because, in my view, it is not acting kindly toward those who
> read the list and attempt to help people, that you would refuse to
> read the documentation. In fact, it initially strikes me as rather
> rude to depend only on others to personally explain solutions (to
> problems that you do not define). Especially so when I consider you
> are depending on the rest of us to read the documentation (source,
> this list, etc), in order to know something you don't. I hope this
> helps to make clear why I found your "I am going to pass" remark so
> exceptional as to comment on it, choosing in this case to completely
> ignore the context of whatever it is that you might want to know.

Seems that ignoring the context has became a habit of yours !



^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  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
  2023-08-09  3:37       ` Michael Heerdegen
  1 sibling, 2 replies; 21+ messages in thread
From: Heime @ 2023-08-09  2:53 UTC (permalink / raw)
  To: Drew Adams
  Cc: Pierre Rouleau,
	Heime via Users list for the GNU Emacs text editor

------- Original Message -------
On Wednesday, August 9th, 2023 at 2:27 PM, Drew Adams <drew.adams@oracle.com> wrote:


> > > > 1- What is the problem that you are trying to solve?
> > > 
> > > 2- If you want to pass something to a function and you want that
> > > something
> > > not evaluated, then: quote it. The function can later evaluate it if it
> > > needs to extract the result of the expression, or it can print it using
> > > a
> > > string formatting function.
> > > 
> > > 3- If #2 is not clear, reading a LISP tutorial will help. Investing time
> > > reading on LISP and Emacs Lisp will help a lot.
> > 
> > I am going to pass
> > (myfunc (macroexpand-all something arg) bfname)
> > 
> > How would I define myfunc ?
> > 
> > Will (macroexpand-all something arg) be in a form of a list (list of names
> > and arguments) or what ?
> 
> 
> As several have said, a Lisp macro takes a list sexp that has a symbol car, that is, something that looks like a function call: (foo...), and it returns a Lisp form - pretty much any kind of Lisp object you like: a string, a symbol, a list, a vector, a character or other number.
> 
> `macroexpand-all` just expands the macro calls at all levels of its FORM argument: the topmost sexp and any sexps inside it - all the way down.
> 
> You've already been told that if you want to pass a Lisp object to a function without it being evaluated then quote it.
> 
> Since you want `macroexpand-all' to first expand your` something' form, you want to quote it after evaluating the `macroexpand-all' call. How to do that is the among the FAQiest FAQs: https://emacs.stackexchange.com/q/7481 IOW, (myfunc` ,(macroexpand-all something arg))

Did not occur to me to quote it.  Still I know what quoting means.

I want to pass other variables to my function, example a a buffer name like so

(myfunc ` ,(macroexpand-all something arg) bfname)

So you want to quote it, but then execute macroexpand-all

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

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.

(myfunc (macroexpand-all something arg) bfname)
 
> As many have suggested to you ... the Elisp Intro manual is your friend, as is 
> the Elisp manual. It has a wealth of clear explanation and unlimited patience.

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.

If you want to help someone, one should not expect a certain result.  Because the
result is not up to you.  The result is determined by the person who receives it.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  2:27     ` [External] : " Drew Adams
  2023-08-09  2:53       ` Heime
@ 2023-08-09  3:37       ` Michael Heerdegen
  2023-08-09  4:13         ` Heime
  2023-08-09  4:28         ` Drew Adams
  1 sibling, 2 replies; 21+ messages in thread
From: Michael Heerdegen @ 2023-08-09  3:37 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams <drew.adams@oracle.com> writes:

> IOW, (myfunc `,(macroexpand-all something arg))

This is equivalent to (myfunc (macroexpand-all something arg))
(what is probably what he wants anyway).

To quote a value you want `',...  but I doubt this is need here.

Michael.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  2:04   ` Heime
  2023-08-09  2:26     ` Corwin Brust
  2023-08-09  2:27     ` [External] : " Drew Adams
@ 2023-08-09  3:39     ` Michael Heerdegen
  2023-08-09  5:06       ` Heime
  2 siblings, 1 reply; 21+ messages in thread
From: Michael Heerdegen @ 2023-08-09  3:39 UTC (permalink / raw)
  To: help-gnu-emacs

Heime <heimeborgia@protonmail.com> writes:

> Will (macroexpand-all something arg) be in a form of a list (list of names
> and arguments) or what ?

Why don't you just try?

Michael.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  2:53       ` Heime
@ 2023-08-09  4:02         ` Pierre Rouleau
  2023-08-09  4:14         ` Drew Adams
  1 sibling, 0 replies; 21+ messages in thread
From: Pierre Rouleau @ 2023-08-09  4:02 UTC (permalink / raw)
  To: Heime; +Cc: Drew Adams, Heime via Users list for the GNU Emacs text editor

> If you want to help someone, one should not expect a certain result.
> Because the
> result is not up to you.  The result is determined by the person who
> receives it.
>
>
Well, to be able to learn, one must be open.  Repeating questions over and
over without showing an effort will turn off any human teacher.  The
advantage of the computer is it won't quit trying to help you.

When someone helps someone else there is always an expectation of respect.
Otherwise these lists would not exist.

There's people with lots of experience and expertise here, lots of patience
too it seems, and they have all provided similar advice.  Try to read other
sources of material, try the examples, try by yourself.  Otherwise you will
always have to ask the same questions and it will take you a lot more time
than what it should.

-- 
/Pierre


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  3:37       ` Michael Heerdegen
@ 2023-08-09  4:13         ` Heime
  2023-08-09  4:36           ` Michael Heerdegen
  2023-08-09  4:28         ` Drew Adams
  1 sibling, 1 reply; 21+ messages in thread
From: Heime @ 2023-08-09  4:13 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs






Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, August 9th, 2023 at 3:37 PM, Michael Heerdegen <michael_heerdegen@web.de> wrote:


> Drew Adams drew.adams@oracle.com writes:
> 
> > IOW, (myfunc `,(macroexpand-all something arg))
> 
> 
> This is equivalent to (myfunc (macroexpand-all something arg))
> (what is probably what he wants anyway).
> 
> To quote a value you want `',... but I doubt this is need here.
> 
> Michael.

This is where things start to be confusing.  When experienced one
get to disagree.  

It is easy to see how one can have difficulties, because according
to some the quoting might not be needed.  So in practice, is it 
needed to quote or not the result of (macroexpand-all something arg) ?



   




^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  2:53       ` Heime
  2023-08-09  4:02         ` Pierre Rouleau
@ 2023-08-09  4:14         ` Drew Adams
  1 sibling, 0 replies; 21+ messages in thread
From: Drew Adams @ 2023-08-09  4:14 UTC (permalink / raw)
  To: Heime; +Cc: Pierre Rouleau,
	Heime via Users list for the GNU Emacs text editor

> 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.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  3:37       ` Michael Heerdegen
  2023-08-09  4:13         ` Heime
@ 2023-08-09  4:28         ` Drew Adams
  1 sibling, 0 replies; 21+ messages in thread
From: Drew Adams @ 2023-08-09  4:28 UTC (permalink / raw)
  To: Michael Heerdegen, help-gnu-emacs@gnu.org

> > (myfunc `,(macroexpand-all something arg))
> This is equivalent to
> (myfunc (macroexpand-all something arg))

You're right, of course. ;-)

Guess I was thinking about putting the
result of evaluation in some structure.
E.g., if you wanted to insert the result
of evaluating (foo) in a list, you'd use
`(,(foo)...), or (list (foo)...).  



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  4:13         ` Heime
@ 2023-08-09  4:36           ` Michael Heerdegen
  2023-08-09  4:54             ` Heime
  0 siblings, 1 reply; 21+ messages in thread
From: Michael Heerdegen @ 2023-08-09  4:36 UTC (permalink / raw)
  To: help-gnu-emacs

Heime <heimeborgia@protonmail.com> writes:

> So in practice, is it needed to quote or not the result of
> (macroexpand-all something arg) ?

The result of the `macroexpand-all' call is an expression (i.e. a list
most the time).  Just a normal list that happens to look like and being
usable as code.

So unless you want 'EXPR instead of EXPR you don't need to quote: the
result will not be evaluated (unless it's the returned expansion of a
macro call, but then you want the evaluation).

As I said, why don't you try?

Michael.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  4:36           ` Michael Heerdegen
@ 2023-08-09  4:54             ` Heime
  2023-08-09 15:21               ` Drew Adams
  0 siblings, 1 reply; 21+ messages in thread
From: Heime @ 2023-08-09  4:54 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs






Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, August 9th, 2023 at 4:36 PM, Michael Heerdegen <michael_heerdegen@web.de> wrote:


> Heime heimeborgia@protonmail.com writes:
> 
> > So in practice, is it needed to quote or not the result of
> > (macroexpand-all something arg) ?
> 
> 
> The result of the `macroexpand-all' call is an expression (i.e. a list
> most the time). Just a normal list that happens to look like and being
> usable as code.

Not according to Drew, who says I got to quote.

In other words, you are saying that macroexpand-all gives me just a normal list 
which is not evaluated before being passed to the function. Correct ?  

And then having a function defined as so

(defun myfunc (expr bfname)

and calling 

(myfunc (macroexpand-all something arg) bfname)

will handle bfname properly.  It will not pick up anything from
the macroexpand-all data.  Am I right ?

> So unless you want 'EXPR instead of EXPR you don't need to quote: the
> result will not be evaluated (unless it's the returned expansion of a
> macro call, but then you want the evaluation).

I am doing (pp-to-string expr) inside

(defun myfunc (expr bfname)
  (apply 'talos (list (pp-to-string expr) bfname)))
 
> As I said, why don't you try?

I tried it, but then others claimed it was not good doing. 
 
> Michael.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  3:39     ` Michael Heerdegen
@ 2023-08-09  5:06       ` Heime
  2023-08-09 15:27         ` [External] : " Drew Adams
  0 siblings, 1 reply; 21+ messages in thread
From: Heime @ 2023-08-09  5:06 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs


------- Original Message -------
On Wednesday, August 9th, 2023 at 3:39 PM, Michael Heerdegen <michael_heerdegen@web.de> wrote:


> Heime heimeborgia@protonmail.com writes:
> 
> > Will (macroexpand-all something arg) be in a form of a list (list of names
> > and arguments) or what ?
> 
> 
> Why don't you just try?
> 
> Michael.

I do not think one can just try it because it is not evident at what instance
in time does the interpreter interpret the output code of a macro.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  4:54             ` Heime
@ 2023-08-09 15:21               ` Drew Adams
  0 siblings, 0 replies; 21+ messages in thread
From: Drew Adams @ 2023-08-09 15:21 UTC (permalink / raw)
  To: Heime, Michael Heerdegen; +Cc: help-gnu-emacs@gnu.org

> > > So in practice, is it needed to quote or not the result of
> > > (macroexpand-all something arg) ?
> >
> > The result of the `macroexpand-all' call is an expression (i.e. a list
> > most the time). Just a normal list that happens to look like and being
> > usable as code.
> 
> Not according to Drew, who says I got to quote.

I misspoke (wrote).  You don't need to quote
in the example you presented - my bad.

I mistakenly thought you were needing to eval
something and quote the result for further
processing.  That's what the link I posted is
about: how to do that.

Sorry for adding to the confusion.

> In other words, you are saying that macroexpand-all gives me just a normal
> list
> which is not evaluated before being passed to the function. Correct ?
> 
> And then having a function defined as so
> 
> (defun myfunc (expr bfname)
> 
> and calling
> 
> (myfunc (macroexpand-all something arg) bfname)
> 
> will handle bfname properly.  It will not pick up anything from
> the macroexpand-all data.  Am I right ?

Yes.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09  5:06       ` Heime
@ 2023-08-09 15:27         ` Drew Adams
  2023-08-09 20:34           ` Heime
  0 siblings, 1 reply; 21+ messages in thread
From: Drew Adams @ 2023-08-09 15:27 UTC (permalink / raw)
  To: Heime, Michael Heerdegen; +Cc: help-gnu-emacs@gnu.org

> > Why don't you just try?
> I do not think one can just try it

Yes, you can.  (This is the beauty of Lisp.)

> because it is not evident at what instance in
> time does the interpreter interpret the output
> code of a macro.

As mentioned, a macro _call_, such as (mymacro...)
is interpreted at that same time any Lisp form is.

What's particular about interpreting a macro call
is that first the call is macroexpanded, according
to the macro definition, and then the expansion
result is interpreted (evaluated) - immediately.
That's all.

If you byte-compile the Lisp source code then the
macro call gets macroexpanded during compilation,
and the result of expansion is then compiled to
produce the byte-compiled code.  In effect, the
macro-call source code disappears and is replaced
by the expansion, in line, and the resulting code
is then byte-compiled.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09 15:27         ` [External] : " Drew Adams
@ 2023-08-09 20:34           ` Heime
  2023-08-09 21:24             ` Drew Adams
  0 siblings, 1 reply; 21+ messages in thread
From: Heime @ 2023-08-09 20:34 UTC (permalink / raw)
  To: Drew Adams; +Cc: Michael Heerdegen, help-gnu-emacs@gnu.org






Sent with Proton Mail secure email.

------- Original Message -------
On Thursday, August 10th, 2023 at 3:27 AM, Drew Adams <drew.adams@oracle.com> wrote:


> > > Why don't you just try?
> > > I do not think one can just try it
> 
> 
> Yes, you can. (This is the beauty of Lisp.)
> 
> > because it is not evident at what instance in
> > time does the interpreter interpret the output
> > code of a macro.
> 
> 
> As mentioned, a macro call, such as (mymacro...)
> is interpreted at that same time any Lisp form is.
> 
> What's particular about interpreting a macro call
> is that first the call is macroexpanded, according
> to the macro definition, and then the expansion
> result is interpreted (evaluated) - immediately.
> That's all.

That's the revelation "immediately".  In other words, keeping 
the actual run-time code produced by a macro is not something
that endures.  Making it quite hard to retain the output as is,
without evaluation.  Consequently I do not see the importance of
calling "(macroexpand (this arg))" rather than just calling the 
(this arg). 

The usefulness of macroexpand seems to be the ability to output
up to a specific expansion level, that's all.

> If you byte-compile the Lisp source code then the
> macro call gets macroexpanded during compilation,
> and the result of expansion is then compiled to
> produce the byte-compiled code. In effect, the
> macro-call source code disappears and is replaced
> by the expansion, in line, and the resulting code
> is then byte-compiled.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09 20:34           ` Heime
@ 2023-08-09 21:24             ` Drew Adams
  2023-08-09 21:32               ` Heime
  0 siblings, 1 reply; 21+ messages in thread
From: Drew Adams @ 2023-08-09 21:24 UTC (permalink / raw)
  To: Heime; +Cc: Michael Heerdegen, help-gnu-emacs@gnu.org

> The usefulness of macroexpand seems to be the ability to output
> up to a specific expansion level, that's all.

Two main uses of macro expansion:

1. For coders, to debug their macro definitions.
Expansion lets you see the code you're telling
the macro to produce.

2. For byte-compilation, so for performance.
As I mentioned the expanded code gets substituted
for the source macro call, in line.  (Nay, its
byte-compilation gets substituted.)

For #1 you as a developer call `macroexpand'.
For #2 code in the byte-compiler calls it (in
effect).

> > If you byte-compile the Lisp source code then the
> > macro call gets macroexpanded during compilation,
> > and the result of expansion is then compiled to
> > produce the byte-compiled code. In effect, the
> > macro-call source code disappears and is replaced
> > by the expansion, in line, and the resulting code
> > is then byte-compiled.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Passing result of macroexpand-all as argument to a function
  2023-08-09 21:24             ` Drew Adams
@ 2023-08-09 21:32               ` Heime
  0 siblings, 0 replies; 21+ messages in thread
From: Heime @ 2023-08-09 21:32 UTC (permalink / raw)
  To: Drew Adams; +Cc: Michael Heerdegen, help-gnu-emacs@gnu.org






Sent with Proton Mail secure email.

------- Original Message -------
On Thursday, August 10th, 2023 at 9:24 AM, Drew Adams <drew.adams@oracle.com> wrote:


> > The usefulness of macroexpand seems to be the ability to output
> > up to a specific expansion level, that's all.
> 
> 
> Two main uses of macro expansion:
> 
> 1. For coders, to debug their macro definitions.
> Expansion lets you see the code you're telling
> the macro to produce.
> 
> 2. For byte-compilation, so for performance.
> As I mentioned the expanded code gets substituted
> for the source macro call, in line. (Nay, its
> byte-compilation gets substituted.)
> 
> For #1 you as a developer call `macroexpand'.
> For #2 code in the byte-compiler calls it (in
> effect).

I think we resolved this whole thing about macros then. 

> > > If you byte-compile the Lisp source code then the
> > > macro call gets macroexpanded during compilation,
> > > and the result of expansion is then compiled to
> > > produce the byte-compiled code. In effect, the
> > > macro-call source code disappears and is replaced
> > > by the expansion, in line, and the resulting code
> > > is then byte-compiled.



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-08-09 21:32 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).