Newsgroups: comp.lang.lisp
From: "Anton van Straaten" <an...@appsolutions.com>
Date: Sun, 22 Feb 2004 23:03:46 GMT
Local: Sun, Feb 22 2004 6:03 pm
Subject: Re: Scheme macros
Pascal Costanza wrote: If you look up "macro transformer" in the index, it points you to a page > Anton van Straaten wrote: > > Pascal Costanza wrote: > >>To me, the conceptual simplicity of CL-style macros is striking: It's > > That's what all of these macro systems are. > R5RS doesn't say so. At least, I don't see where the term "macro which contains the following definition (Sec. 4.3, Macros): "The set of rules that specifies how a use of a macro is transcribed into a I don't think it's hiding anything. Do you think otherwise? > >>Once understood, it's clear that you can do anything I agree the docs don't make it easy to get into at first. I learned > >>with this conceptual model. > > The same is true of syntax-case. > Of course, I will take your word for that. But I still don't understand syntax-case (up to a point - I'm not an expert by any means) after first learning and using syntax-rules for some time, and having previously been familiar with defmacro. I think syntax-rules makes a good starting point, because it teaches the hygienic pattern matching approach in a simpler context. That same approach is used by syntax-case, but augmented with a much more powerful procedural syntax manipulation capability. But I'll ignore my own advice and take a stab at explaining syntax-case, Start with defmacro, and imagine that instead of quoting syntax using An important thing to note here is that a syntax object "understands" the Within a syntax expression of the form (syntax ...), any references to macro (define-syntax and2 The (lambda (x) ...) binds a syntax object to x, representing the syntax of Within the above syntax-case expression, there's a single pattern and a ((_ x y) The underscore in (_ x y) represents the name of the macro - you could also In the above, since x and y are macro variables (strictly speaking, "pattern I think I'll stop there for now, since I have other things to do! I've > > Syntax-rules is not hard to learn. If anything, it suffers from being I don't accept that "conceptual simplicity is lost" with syntax-rules. It's > > almost too simple; as well as from lacking good, short introductory > > material. You specify a pattern, and specify the syntax that should replace > > that pattern. That's all there is to it. > Examples like those given in a different approach, which in some ways is conceptually simpler than defmacro, since it doesn't require the user to manually keep track of the different levels at which the macro operates. The pitfalls you mention may indeed be flaws in syntax-rules - I'm not familiar enough with them to comment - but I find that syntax-rules works very well for many kinds of macros, better than defmacro in fact. Of course, the latter claim is hardly ever going to be accepted by someone > Here are the examples from that reference implemented with DEFMACRO: I'm not sure what you mean about not seeing the problem. One of the > (defun foo-f (x) > (defmacro foo-m (x) > (defmacro bar-m2 (var &body body) > I really don't see the problem. Seriously not. problems mentioned in the article is that syntax-rules pattern variables don't shadow. I don't know if there's a justification for that, or it's simply a bug in the design of syntax-rules. But you usually get an error if you make this mistake, and it's easy to fix, and easy to avoid. It doesn't mean that syntax-rules is not useful, and it's still better than defmacro, which you can't dispute until you've learned syntax-rules. ;) > > Syntax-case is more complex, and I do think that's a drawback when In some respects, yes, but that's not what I really meant. It's easy to compared > > to defmacro. It increases the temptation to conclude the following: > >>And it immediately makes me wonder whether it is really worth it. > > I might wonder something similar if I were a Python programmer looking > Lisp and Scheme bring you metacircularity. As soon as Pythonistas write > Do you really think that syntax-case is an equally important step forward? look at something from the outside and find reasons not to try it, and that was my main point. But the points you've been picking on don't seem very substantial to me - it seems as though you're looking for reasons to ignore these systems, rather than looking for reasons you might want to learn them. To conclude from the points you've raised that these systems can be ignored, seems to me to throw a bunch of babies out with the bathwater. (They're much cuter babies than that warty defmacro baby, too! ;) Of course, a CL programmer who wants to write standard CL code, obviously > >>BTW, what you really need to make something like DEFMACRO work is, on I'm familiar with why people claim it's an issue, but in practice I think > >>top of that, of course quasiquotation, GENSYM/MAKE-SYMBOL or > >>string->uninterned-symbol and most probably a Lisp-2. > > I don't see that Lisp-2 is an issue. it's not significantly worse than the issue of hygiene in defmacros in general. As I've said and defended here once before, Lisp-1 can express any Lisp-2 program, simply by changing any conflicting names so as not to conflict - a conceptually trivial transformation, with consequences which are primarily subjective. It would have an impact on porting Lisp-2 macros to Lisp-1, but it doesn't limit what you can easily express in Lisp-1. Put another way, having the ability to accidentally compensate for hygiene > Here it helps that a Lisp-2 seperates variables and functions by Mmm, asterisks. This, to me, is why the whole Lisp-1/2 debate is moot. The > default. Variables are usually not important parts of an application's > ontology. If they are, the convention in Common Lisp is to use proper > naming schemes, like asterisks for special variables. Effectively, this > creates a new namespace. solution is simply Lisp-N, where you can define namespaces, modules, etc. and control how they're used. See PLT Scheme etc. > 4. The fourth example can be solved with a proper GENSYM for "use" in The phrase "proper GENSYM" is an oxymoron. GENSYM operates at a strangely > the "contorted" macro. low level of abstraction. Why don't you use GENSYM when declaring normal lexical variables in a procedure? Rhetorical question, of course - the point is, GENSYM is a kludge. It's not a particularly onerous one, but it's part of what makes defmacro worth improving on. > Some while ago, I wanted to experiment with continuations in Scheme. We're straying far afield here. ;) But I'll give my opinion about > Apart from the fact that not all Schemes seem to implement continuations > fully and/or correctly (see > http://sisc.sourceforge.net/r5rspitresults.html ), the fact that the > respective documentations make me feel uneasy about whether I have to > relearn programming techniques for totally unrelated areas is a clear > downside IMHO. continuations, too. Re the quality of implementations, once again you're looking at edge cases. Forget about those, they're not important, except in, well, edge cases. All of the major Schemes either support continuations well, or tell you when they don't - e.g., some of the Scheme to C compilers deliberately provide restricted continuations. As far as relearning programming techniques goes, first and foremost, Scheme is one of very few languages - along with SML/NJ, Stackless Python, For ordinary programming, though, continuations are more or less > [...] Maybe - let's talk once you've tried syntax-rules. But you gave a clue to > > The result is that it's actually easier to reason about syntax-rules > > macros - which makes them easier to write, and easier to read. As a result, > > and also because of the enforced hygiene, they're less error-prone. > I don't mind using DEFMACRO for simple things. I don't find them hard to your reading & writing process for DEFMACRO when you said that when reading a syntax-rules macro, you were immediately worrying about which level the various tokens were at. You've learned to look for, and expect something that, with syntax-rules, you can simply forget about. You don't do these things when writing ordinary functions - why do you put up with it when writing macros? What would you think of Lisp if you had to use gensym to initialize every variable you use? You've simply become very used to a low-level technique, so that you don't believe there's any need for a higher level technique. > What stands in the way of implementing syntax-case on top of DEFMACRO? I don't think it would make much sense. The implementation of syntax > (This is not a rhetorical question.) objects has little do with what defmacro does. The pattern matching forms of syntax-case might be defined via DEFMACRO at the surface level, but their definitions deal with syntax objects, so there'd be little for defmacro to do once the syntax objects had been constructed. It wouldn't help much when constructing the syntax objects, either, since the 'syntax' form doesn't use defmacro syntax, and I can't see any point in converting it internally. The reason that it's easy to implement DEFMACRO in syntax-case is that a Anton You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||