lilypond-user
[Top][All Lists]
Advanced

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

Re: A new Scheme tutorial


From: Jean Abou Samra
Subject: Re: A new Scheme tutorial
Date: Mon, 25 Jul 2022 23:08:41 +0200


> Le 25 juil. 2022 à 14:51, David Kastrup <dak@gnu.org> a écrit :
> 
> Jean Abou Samra <jean@abou-samra.fr> writes:
> 
>>>> Le 25 juil. 2022 à 09:01, Andrew Bernard <andrew.bernard@mailbox.org> a 
>>>> écrit :
>>> 
>>> 
>>> Hello Jean,
>>> 
>>> This is a great effort.
>>> 
>>> A couple of suggestions. I suppose there are a few web pages with
>>> lists of recommended texts for Scheme, but I think it would be great
>>> if you added this one to the 'where to go from here' section:
>>> 
>>> Teach Yourself Scheme in Fixnum Days (ds26gte.github.io)
>>> 
>> 
>> 
>> Gosh, it seems to teach Lisp-style non-hygienic macros instead of
>> syntax-rules/syntax-case. That’s heresy against my religion! OK, I
>> stop now :-)
> 
> syntax-rules/syntax-case introduce a completely new and arbitrary syntax
> intended to be human-readable.  That's sort of a counterthesis to the
> LISP philosophy of representing programs by the data representation of
> their parse tree, skipping a human-readable abstraction for the sake of
> making it easy to programmatically generate and analyze programs.
> 
> Macros, in contrast, are just a flag on functions telling the evaluator
> "evaluate the function result instead of its arguments".  That is an
> almost trivial tweak.

Modulo the fact that IIRC, Guile 1 would only run the macro the first time the 
form was evaluated, but I see what you mean.


> More complex, indeed, is the quasiquote mechanism
> that operates to a good degree in the LISP reader and makes it
> comparatively easy to handle the creation of material suitable as macro
> body.
> 
> In contrast to syntax-rules/syntax-case this reflects more a philosophy
> rather than a religion since it isn't arbitrary.  Using it is more a
> matter of understanding rather than learning it.


There are two mostly unrelated parts in the Scheme macro system that 
differentiate it from the traditional Lisp system: the pattern matching 
language, and hygiene.

The first part is definitely not all lilies and roses. It’s weird to have a 
separate namespace for the pattern variables bound by syntax-case. It’s weird 
that the primitive way to analyze syntax objects is not a set of simple 
procedures like syntax-pair?, syntax-car, but only syntax-case pattern 
matching, against the traditional Scheme principle that complex tools (like 
syntax-case) are built at will on top of very simple tools. It’s weird that 
syntax pairs aren’t normal pairs, so you can’t use list functions on them 
directly. It’s weird that #'(pat …) doesn’t return a syntax list but just a 
plain list (at least in Guile, didn’t check the standard).

Still, this macro system gives you a form of lexical scoping and hygiene, and 
allows things like renaming syntax keywords when importing them, which is 
really nifty and the main reason why I prefer writing syntax-rules/case macros. 
I like the principle of annotated symbols containing scope information. It’s 
not that I’m fond of the tools provided to manipulate them.

I tend to think of Scheme as a language with elegant syntax on top of clumsy 
data structures (alist lookup is linear, etc). In this case, it’s sort of the 
opposite…






reply via email to

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