all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Philip Kaludercic <philipk@posteo.net>
Cc: Yuri Khan <yuri.v.khan@gmail.com>,
	Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: macros and macroexpand
Date: Mon, 07 Aug 2023 20:56:18 +0000	[thread overview]
Message-ID: <SZZBhemwLyHss2S7BUoinPQ9yC0f0c4oBwaJxJY50f4Cev_XMrWoiW8uZPA-TBTbKCwtHTICUf9KT26wULOyBjjj4iIr5Lr4_3SFNcEfwhg=@protonmail.com> (raw)
In-Reply-To: <87sf8usjia.fsf@posteo.net>


------- Original Message -------
On Tuesday, August 8th, 2023 at 8:08 AM, Philip Kaludercic <philipk@posteo.net> wrote:


> Heime heimeborgia@protonmail.com writes:
> 
> > Sent with Proton Mail secure email.
> > 
> > ------- Original Message -------
> > On Tuesday, August 8th, 2023 at 2:22 AM, Philip Kaludercic philipk@posteo.net wrote:
> > 
> > > Heime heimeborgia@protonmail.com writes:
> > > 
> > > > Sent with Proton Mail secure email.
> > > > 
> > > > ------- Original Message -------
> > > > On Monday, August 7th, 2023 at 11:46 PM, Yuri Khan yuri.v.khan@gmail.com wrote:
> > > > 
> > > > > On Mon, 7 Aug 2023 at 18:04, Heime heimeborgia@protonmail.com wrote:
> > > > > 

> > > > (defmacro adder (mopi mopj)
> > > > `(+ ,(cl-second mopi) ,(cl-third mopj)))
> > > > 
> > > > (princ (pp-to-string '(adder (* 3 5) (* 5 7)) ))
> > > 
> > > ^
> > > don't do this
> > > 
> > > If you quote an expression, it won't be evaluated or macro-expanded any
> > > further. You can sort-of think of a macro like a kind of inline
> > > function call. The evaluation would go along these lines:
> > > 
> > > (princ (pp-to-string (adder (* 3 5) (* 5 7))))
> > > 
> > > will be transformed into this at macro-expansion time, and evaluation
> > > would do this:
> > > 
> > > (princ (pp-to-string (+ (cl-second '(* 3 5)) (cl-third '(* 5 7)))))
> > > (princ (pp-to-string (+ 3 7)))
> > > (princ (pp-to-string 10))
> > > (princ "10\n")
> > > "10\n"
> > 
> > What I want to do is print the code made by adder of its final expansion code.
> > Rather than the last evaluation of 10, I want to print (+ 3 7).
> > 
> > Can my print command be modified in such a way that the message shows (+ 3 7) ?
> > IT seems that I would need to use macroexpand-all, to get to the final unevaluated
> > sexp.
> 
> 
> You can modify your macro, to return a quoted expression.
> 
> (defmacro adder (mopi mopj)
> `'(+ ,(cl-second mopi) ,(cl-third mopj)))
> ^
> note this

That means that you do not evaluate the sexp.  I see this more of a hack
to be able to print the sexp as elisp code, rather than the way a macro
will be coded for practical use.  Am I right ?

What I want to have is a function that is able to print the end sexp result
produced by a practically implemented macro, without evaluating the expression. 

> This is synonymous with
> 
> (defmacro adder (mopi mopj)
> (list 'quote (list '+ (cl-second mopi) (cl-third mopj))))
> 
> which makes sense, if you keep in mind that the result of evaluating the
> macro is what replaces the macro expression in the syntax tree.
> 
> > > > I would not do
> > > > 
> > > > (princ (pp-to-string (macroexpand '(adder (* 3 5) (* 5 7))) ))



  reply	other threads:[~2023-08-07 20:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 11:03 macros and macroexpand Heime
2023-08-07 11:46 ` Yuri Khan
2023-08-07 12:43   ` Heime
2023-08-07 14:22     ` Philip Kaludercic
2023-08-07 18:06       ` Heime
2023-08-07 20:08         ` Philip Kaludercic
2023-08-07 20:56           ` Heime [this message]
2023-08-07 22:10             ` Emanuel Berg
2023-08-08 20:35               ` Heime
2023-08-08  5:57             ` Philip Kaludercic
2023-08-07 14:28 ` [External] : " Drew Adams
2023-08-07 18:22   ` Heime
2023-08-07 19:04   ` Emanuel Berg
2023-08-07 18:59 ` Emanuel Berg

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='SZZBhemwLyHss2S7BUoinPQ9yC0f0c4oBwaJxJY50f4Cev_XMrWoiW8uZPA-TBTbKCwtHTICUf9KT26wULOyBjjj4iIr5Lr4_3SFNcEfwhg=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=philipk@posteo.net \
    --cc=yuri.v.khan@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.