unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: [External] : Re: Why is defun not executed during load-file?
Date: Mon, 31 May 2021 21:20:32 +0200	[thread overview]
Message-ID: <87a6oad81r.fsf@zoho.eu> (raw)
In-Reply-To: SA2PR10MB4474686FEA39CFCF4675521BF33F9@SA2PR10MB4474.namprd10.prod.outlook.com

Drew Adams wrote:

>>>> Also, writing macros compared to writing functions
>>>> typically involves more bugs...
>>>
>>> Why do you think so? [...]
>> 
>> Maybe because it involves an extra layer, writing something
>> that will write something that will do something instead of
>> writing something that will do something...
>> 
>> Just keep on adding layers. Write something to write
>> something to write something ... etc. It gets more
>> difficult for each level added, is what we think.
>
> Fair enough; reasonable argument.
>
> But I still think the perceived difficulty comes from
> relative lack of practice. There are only 2 levels/layers
> involved. And they're completely separate: (1)
> macro-expansion of a sexp to a sexp, and (2) evaluation of
> the sexp resulting from #1.
>
> You write lots of Lisp functions. And you no doubt think
> nothing of adding "layers" by having a function that calls
> a function that calls a function... Even inhibiting
> evaluation with `quote' here and there doesn't seem weird,
> once a novice practices a bit and gets used to it. But all
> of that is (can be) really quite complex.
>
> It's just that you do that all the time - you're used to it.
> You don't write Lisp macros all the time.
>
> The macro-expansion step is the only part that's a bit
> unusual - it's different from most of the Lisp code
> you write.
>
> Think of that step as just replacing one sexp by another.
> The input sexp has the form of a Lisp function call:
> a non-empty list whose car is a symbol.
>
> The output is normally a sexp of the same form, but it need
> not be - it can be any Lisp value (any list, vector, string,
> symbol, number, buffer, frame, syntax table, keymap,...).
> As far as step #1 is concerned, its result need not even be
> something that can be evaluated - or even read -
> without error.
>
> And you have Lisp completely at your disposal, for creating
> the output sexp, given the input sexp.
>
> Once you have the macro-expansion step defined, the job's
> typically done. What's left is to verify that the output
> sexp _evaluates_ to the result you want - and that, for
> every possible input.
>
> That is, because the result of macro-expansion (#1) is
> typically evaluated, you do have to worry about that
> evaluation step (#2), yes.
>
> But if you only ever used `macroexpand' of sexp to sexp to
> sexp to sexp,... then you wouldn't need to bother with that
> worry. You'd just be transforming one list with a symbol car
> to another, to another, to another,...
>
> Macro-expansion isn't evaluation; it's reduction.
> Lisp evaluation rules don't apply to producing the output
> sexp from the input sexp. What rules do apply?
> Whatever rules you like. The only rule underlying it all is
> that the input needs to be a list with a symbol car.
>
> For those used to purely functional programming, that's all
> macro-expansion is: just reduction - term rewriting. You can
> look at it as a rewrite rule from input patterns to output
> patterns. But the rule can be implemented any way you like,
> using any Lisp code.

Hm ... interesting. Yeah, maybe we should start do that more?

But I'm unsure even what is the entry point...

What kind of things or problems could or should you solve
with macros?

-- 
underground experts united
https://dataswamp.org/~incal




  reply	other threads:[~2021-05-31 19:20 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30 22:48 Why is defun not executed during load-file? Drew Adams
2021-05-30 22:57 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-31  2:05   ` [External] : " Drew Adams
2021-05-31  2:56     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-31  5:05       ` Drew Adams
2021-05-31 19:20         ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2021-05-31 19:47           ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-31 20:09             ` Marcin Borkowski
2021-06-07  2:19             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-07  6:27               ` Jean Louis
2021-06-07 14:18               ` FW: " Drew Adams
2021-06-07 14:41                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-31 21:40           ` Example use of macro to minimize and generalize the code Jean Louis
2021-05-31 23:37             ` Michael Heerdegen
2021-05-31 23:59               ` Jean Louis
2021-06-01  0:34                 ` Michael Heerdegen
2021-06-01  0:39                   ` Jean Louis
2021-06-01  0:59                     ` Michael Heerdegen
2021-06-01  1:25                       ` Jean Louis
2021-06-01 14:02                         ` Michael Heerdegen
2021-06-01 16:33                           ` Jean Louis
2021-06-01 16:54                             ` Yuri Khan
2021-06-01 17:24                               ` Jean Louis
2021-06-01 17:57                                 ` Yuri Khan
2021-06-01 18:12                                   ` Jean Louis
2021-05-31 21:45           ` Example use of macro to minimize and generalize the code (2) Jean Louis
2021-05-31 21:48           ` [External] : Re: Why is defun not executed during load-file? Michael Heerdegen
2021-05-31 23:41           ` Drew Adams

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6oad81r.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).