help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FW: [External] : Re: Why is defun not executed during load-file?


From: Drew Adams
Subject: FW: [External] : Re: Why is defun not executed during load-file?
Date: Mon, 7 Jun 2021 14:18:56 +0000

> >> Hm ... interesting. Yeah, maybe we should start do that more?
> >
> > Not really: it's better to avoid macros when you can.
> > But it's better to use macros than to use `eval`.
> 
> Ah, that's what I thought all along but it sounded cool when
> Mr Adams said it wasn't evaluated anymore but reduced (?) ...

Mr. Adams also said:

  If you mean use `defmacro' more or something, then let
  me be clear that I'm NOT suggesting that.  I'm not
  suggesting that people should define more Lisp macros.

  In general, don't define a macro if a function will do
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  what you want.

  I just wanted to point out that I think the supposed
  difficulty or bugginess of defining macros is due partly
  (largely?) to the fact that we (all of us) write macros
  much less often than we write functions.

> Can one summarize in human language without references to Lisp
> perhaps when macros are used? I used them so seldom I don't
> know why people use them, even. I guess I did so good now I'm
> ignorant instead.

Syntax transformation: sexp1 to sexp2, followed typically
(and automatically) by evaluation of sexp2.

Without the evaluation step (i.e., with only "expansion"),
a macro just substitutes one sexp (that's an expression -
syntax) for another.

When do you want to do syntax transformation?  Typically
to define a domain-specific language (which nevertheless
has Lisp-like syntax).  And "DSL" here can mean just
define some accessor functions (macros) that speak more
directly to the purpose/intent/meaning of the thing
accessed.

Another typical use is to define a control structure,
that is, something that need not evaluate all of its
args before invoking the body.  E.g., a conditional or
other predicate.  You can't define something like `if'
with `defun' in Elisp.  You can defined it as a macro.

I said all of this before, with examples:

https://lists.gnu.org/archive/html/help-gnu-emacs/2021-05/msg01157.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]