Re: on lisp and scheme macros
Jose A. Ortega Ruiz j...@gnu.org writes: Hi Jose, I think that Common Lisp macros are, strictly speaking, more powerful than Scheme macros, but I don't have a citation. That's only true for syntax-rules macros. syntax-case macros, which most schemes provide and are required by R6RS, are, strictly speaking, more powerful than CL macros. I don't know scheme macros, so could you please explain why they are more powerful? What can you do with a syntax-case macro what you cannot do with a Common Lisp (or Clojure) macro? Wikipedia lists syntax-case as hygienic macro system, which would make it less powerful than CL macros, because if that was true, you could not write anaphoric macros with it. Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
On Tue, 2011-12-06 at 16:09 +0100, Tassilo Horn wrote: Wikipedia lists syntax-case as hygienic macro system, which would make it less powerful than CL macros, because if that was true, you could not write anaphoric macros with it. You can write anaphora with syntax-case. In fact, defmacro itself can be defined as a simple syntax-case macro. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Stephen Compall stephen.comp...@gmail.com writes: On Tue, 2011-12-06 at 16:09 +0100, Tassilo Horn wrote: Wikipedia lists syntax-case as hygienic macro system, which would make it less powerful than CL macros, because if that was true, you could not write anaphoric macros with it. You can write anaphora with syntax-case. In fact, defmacro itself can be defined as a simple syntax-case macro. Ok, I see. I'm still keen to see a simple syntax-case example demonstrating what you simply cannot do with defmacro. In the mean-time, I've found some post about Racket's macro implementation: http://blog.racket-lang.org/2011/04/writing-syntax-case-macros.html That says the fundamental difference between defmacro and syntax-case macros is that the latter instead of dealing with plain symbols, you're dealing with these syntax values (called “identifiers” in this case) that are essentially a symbol and some opaque information that represents the lexical scope for its source. Do I see it correctly that the following Common Lisp defmacro is broken because of that missing lexical scope? --8---cut here---start-8--- * (defun my-plus (rest xs) (apply #'+ xs)) MY-PLUS * (defmacro foo (rest xs) `(my-plus ,@xs)) FOO * (foo 1 2) 3 * (labels ((my-plus (rest xs) (apply #'- xs))) (foo 1 2)) -1 ;; Ouch! my-plus should not shadow macro expansion internals! --8---cut here---end---8--- Here, the local function `my-place' captures the global definition of `my-plus'. First, I've thought I could easily get rid of that issue by using my-plus's package qualified name, but I was wrong: --8---cut here---start-8--- * (defmacro foo (rest xs) `(common-lisp-user::my-plus ,@xs)) FOO * (labels ((my-plus (rest xs) (apply #'- xs))) (foo 1 2)) -1 --8---cut here---end---8--- Am I doing something wrong, or is there no way to avoid that capture in CL? (Possibly, CL explicitly forbids rebinding standard CL function names for exactly that reason.) That said, in Clojure the example works fine, because everything inside the macro expansion is qualified. --8---cut here---start-8--- user (defmacro foo [ exps] `(+ ~@exps)) #'user/foo user (foo 1 2) 3 user (let [+ #(apply - %)] (foo 1 2)) 3 user (macroexpand '(foo 1 2)) (clojure.core/+ 1 2) --8---cut here---end---8--- And the other way round, passing functions into macros, works also fine. For example, here the rebound + shadows clojure.core/+, which is clearly intended. (Of course, this works fine in CL, too). --8---cut here---start-8--- user (defmacro bar [x args] `(~x ~@args)) #'user/bar user (let [+ #(apply - %)] (bar + 1 2)) -1 --8---cut here---end---8--- Does that mean that Clojure's defmacro is aware of the lexical scope as well and is therefore equally powerful as Scheme's syntax-case? Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Does that mean that Clojure's defmacro is aware of the lexical scope as well and is therefore equally powerful as Scheme's syntax-case? Bye, Tassilo In my implementation of syntax-rules/syntax-case, I did essentially the same thing as syntax-quote (had to reimplement it as there is no programmatic interface for it as far as I'm aware), and it seemed to work fine. Brian -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Hi Tassilo, On Tue, Dec 06 2011, Tassilo Horn wrote: Jose A. Ortega Ruiz j...@gnu.org writes: Hi Jose, I think that Common Lisp macros are, strictly speaking, more powerful than Scheme macros, but I don't have a citation. That's only true for syntax-rules macros. syntax-case macros, which most schemes provide and are required by R6RS, are, strictly speaking, more powerful than CL macros. I don't know scheme macros, so could you please explain why they are more powerful? What can you do with a syntax-case macro what you cannot do with a Common Lisp (or Clojure) macro? In general, syntax-case lets you manipulate first-class syntax objects, whereby all kind of neat tricks are possible out of the box. You gain in expressivity. This is a good overview: http://blog.racket-lang.org/2011/04/writing-syntax-case-macros.html Wikipedia lists syntax-case as hygienic macro system, which would make it less powerful than CL macros, because if that was true, you could not write anaphoric macros with it. It's hygienic by default, but offers ways of breaking hygiene. As a matter of fact, it's possible to define defmacro using syntax-case (see, e.g., https://mercure.iro.umontreal.ca/pipermail/gambit-list/2007-March/001195.html), and then you can use defmacro in Scheme too :) It's also possible to implement hygiene on top of defmacro (with the help of CLOS's symbol-macrolet: http://www.p-cos.net/documents/hygiene.pdf), but it's much more convoluted (and, IIRC, some of the syntax API is still missing in that long paper). Even if you don't buy the expressivity argument, i think we can agree that syntax-case macros are, at least, as powerful as CL macros. Cheers, jao -- Humans think they are smarter than dolphins because we build cars and buildings and start wars etc., and all that dolphins do is swim in the water, eat fish and play around. Dolphins believe that they are smarter for exactly the same reasons. -Douglas Adams -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Jose A. Ortega Ruiz j...@gnu.org writes: Hi Jose, I don't know scheme macros, so could you please explain why they are more powerful? What can you do with a syntax-case macro what you cannot do with a Common Lisp (or Clojure) macro? In general, syntax-case lets you manipulate first-class syntax objects, whereby all kind of neat tricks are possible out of the box. You gain in expressivity. This is a good overview: http://blog.racket-lang.org/2011/04/writing-syntax-case-macros.html See my last post. ;-) It's also possible to implement hygiene on top of defmacro (with the help of CLOS's symbol-macrolet: http://www.p-cos.net/documents/hygiene.pdf), but it's much more convoluted (and, IIRC, some of the syntax API is still missing in that long paper). Would that solve the issue I've broad up in my last post, where the `foo' macro expansion uses the local `my-plus' definition instead of the global one? If I'm not doing anything wrong there, then that effectively would mean that you cannot guarantee that a CL macro does what it should as soon as it uses anything that's not defined in the COMMON-LISP package (because those things mustn't be rebound). In that case, I'd even by the powerfulness argument. Even if you don't buy the expressivity argument, i think we can agree that syntax-case macros are, at least, as powerful as CL macros. Sure, I'm not trying to argument in favour of either one. I'm just interested in the differences. Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
On Sat, Dec 03 2011, Stuart Sierra wrote: I think that Common Lisp macros are, strictly speaking, more powerful than Scheme macros, but I don't have a citation. That's only true for syntax-rules macros. syntax-case macros, which most schemes provide and are required by R6RS, are, strictly speaking, more powerful than CL macros. jao -- I went to the woods because I wished to live deliberately, to front only the essential facts of life, and see if I could not learn what it had to teach, and not, when I came to die, discover that I had not lived. -Henry David Thoreau, naturalist and author (1817-1862) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Em 12/04/11 03:16, Razvan Rotaru escreveu: Wow. I didn't thought this was possible. You know, I have seen a lot of people saying that scheme macros are more powerfull, citing the fact that scheme also has lisp macros, while it's not possible to do it the other way around. Of course it's possible. I think it's mostly like training wheels on a bike and the like: defmacro is some kind of atom macro system you can use to do anything you can imagine, but some things are hard to do, and the scheme system is just making the common cases easier to do right. I have been reading the Guile 2.0 documentation (very much worth a read, as it's the first Guile with a VM and other languages than Scheme, e.g. Emacs lisp) and I think this and that (and Clojure) show very well that good lisps is more a case of sensible defaults (Guile: very very easy to integrate in C; Clojure: JVM as an asset, immutable by default and mutability as an option...) than anything else that makes a lisp better or worse. You can basically do everything in every lisp, but defaults really matter. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
You might be interested in the paper 'Fortifying Macros': http://www.ccs.neu.edu/scheme/pubs/icfp10-cf.pdf syntax-parse is very cool and can give good error messages if the user makes a mistake when using the macro. About a year ago I tried making an implementation of a system like syntax-parse for Clojure: https://github.com/qbg/syntax-rules Once my development box is revived, I intend to work on a Clojure 1.3 very of it with a simpler implementation. One of the issues I've encountered when trying to use pattern matching based macros with Clojure is that idiomatic Clojure syntax is very flat, so you need to extend Scheme's syntax-rules before you able to write a small let macro. I can't speak for Rich, but code style macros represent a superset of pattern matching macros, and are also much easier to implement. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
on lisp and scheme macros
Hi everyone, I was searching the web these days trying to find out more about these two macro systems and understand their differences, and why one is preferable over the other (or not). I'd like to share with you some ideas, and hopefully get some opinions back as well. Coming from the lisp side, and without much knowledge on scheme macros, I'm also trying to decide for myself whether scheme macros can have a (practical) advantage. One good point (found here http://lambdagrok.wikidot.com/forum/t-194636) I think explains it pretty well: lisp macros merely transform a list into another, while scheme macros use a pattern matching sub- language to apply transformations on the input syntax, and produce new syntax. I think this puts the finger on the spot. It seems to me that with macros, scheme breaks out of the homoiconicity of lisp, and opens up a new array of possibilities: define new languages with bdifferent/b syntax (while lisp allows new languages but with the same syntax). I'm saying this by looking at Racket and the direction it has chosen to go (have a look at Typed Scheme and Datalog). This looks like the world turned upside down: the pattern matching macro system is the essence of the system, and scheme is just another language defined with it. The list is not that important anymore, since it's not so essential for the macro system. Now, I have read some opinions which say that most who choose the scheme macros, make it for the pattern matching abilities and not for the hygienic part. This seems like a reasonable thing to do, since I don't hear lispers complain about unhygienicity. If there are people out there who had some practical experience with scheme macros, I hope they read this post and share some thoughts. I have a feeling that there's an additional gain with scheme macros: debugging information given by the system when something goes wrong. But it's only a feeling, I know too little of this subject to be sure. Macros are hard to debug. The stacktrace displayed by clojure does not contain information related to macro code. It's probably hard to do. My feeling relates to the fact that in scheme macro processing is not arbitrary, but rather strictly defined and under control. So I'm thinking that this gives scheme more control over what's going on in a macro and also enables scheme to give me more information in a stacktrace. I'd love to hear other opinions on this. Another point I find peculiar is the small attention that scheme macros got during all these years. I wonder why it's like that. It could be scheme's low score for practical stuff, but then again I don't know of another language that borrows these kind of macros. Does anybody know? And lastly, a question to Rich Hickey, should he read this post: what is the reasoning behind the choice of lisp macros over scheme's? Cheers, Razvan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
I think that Common Lisp macros are, strictly speaking, more powerful than Scheme macros, but I don't have a citation. -S -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Stuart Sierra the.stuart.sie...@gmail.com writes: I think that Common Lisp macros are, strictly speaking, more powerful than Scheme macros, but I don't have a citation. Let over Lambda is essentially a huge essay about why there's and will never be anything as powerful than the CL macro system. Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
This talk of Scheme macros is a little weird: are we talking syntax-case, explicit-renaming, or unhygienic defmacro? Scheme has them all. There are also implementation-specific mechanisms for writing reader macros: what's left? On Dec 3, 2011, at 14:57, Stuart Sierra the.stuart.sie...@gmail.com wrote: I think that Common Lisp macros are, strictly speaking, more powerful than Scheme macros, but I don't have a citation. -S -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Scheme style macros in Clojure: https://github.com/qbg/syntax-rules Scott On Sat, Dec 3, 2011 at 1:20 PM, Razvan Rotaru razvan.rot...@gmail.comwrote: Hi everyone, I was searching the web these days trying to find out more about these two macro systems and understand their differences, and why one is preferable over the other (or not). I'd like to share with you some ideas, and hopefully get some opinions back as well. Coming from the lisp side, and without much knowledge on scheme macros, I'm also trying to decide for myself whether scheme macros can have a (practical) advantage. One good point (found here http://lambdagrok.wikidot.com/forum/t-194636) I think explains it pretty well: lisp macros merely transform a list into another, while scheme macros use a pattern matching sub- language to apply transformations on the input syntax, and produce new syntax. I think this puts the finger on the spot. It seems to me that with macros, scheme breaks out of the homoiconicity of lisp, and opens up a new array of possibilities: define new languages with bdifferent/b syntax (while lisp allows new languages but with the same syntax). I'm saying this by looking at Racket and the direction it has chosen to go (have a look at Typed Scheme and Datalog). This looks like the world turned upside down: the pattern matching macro system is the essence of the system, and scheme is just another language defined with it. The list is not that important anymore, since it's not so essential for the macro system. Now, I have read some opinions which say that most who choose the scheme macros, make it for the pattern matching abilities and not for the hygienic part. This seems like a reasonable thing to do, since I don't hear lispers complain about unhygienicity. If there are people out there who had some practical experience with scheme macros, I hope they read this post and share some thoughts. I have a feeling that there's an additional gain with scheme macros: debugging information given by the system when something goes wrong. But it's only a feeling, I know too little of this subject to be sure. Macros are hard to debug. The stacktrace displayed by clojure does not contain information related to macro code. It's probably hard to do. My feeling relates to the fact that in scheme macro processing is not arbitrary, but rather strictly defined and under control. So I'm thinking that this gives scheme more control over what's going on in a macro and also enables scheme to give me more information in a stacktrace. I'd love to hear other opinions on this. Another point I find peculiar is the small attention that scheme macros got during all these years. I wonder why it's like that. It could be scheme's low score for practical stuff, but then again I don't know of another language that borrows these kind of macros. Does anybody know? And lastly, a question to Rich Hickey, should he read this post: what is the reasoning behind the choice of lisp macros over scheme's? Cheers, Razvan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
On Sun, 04 Dec 2011 00:08:36 +0100 Tassilo Horn tass...@member.fsf.org wrote: Stuart Sierra the.stuart.sie...@gmail.com writes: I think that Common Lisp macros are, strictly speaking, more powerful than Scheme macros, but I don't have a citation. Let over Lambda is essentially a huge essay about why there's and will never be anything as powerful than the CL macro system. I'd love to see an example because I digged into Scheme macros for my studies, and you can definitely break out of hygienic macros if you want to. Which seems reasonable to me, to have a safe system by default and then the ability to break out. Just like lexical and dynamic scope in Clojure. regards, Marek -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: on lisp and scheme macros
Wow. I didn't thought this was possible. You know, I have seen a lot of people saying that scheme macros are more powerfull, citing the fact that scheme also has lisp macros, while it's not possible to do it the other way around. On Dec 4, 2:06 am, Scott Jaderholm jaderh...@gmail.com wrote: Scheme style macros in Clojure:https://github.com/qbg/syntax-rules Scott On Sat, Dec 3, 2011 at 1:20 PM, Razvan Rotaru razvan.rot...@gmail.comwrote: Hi everyone, I was searching the web these days trying to find out more about these two macro systems and understand their differences, and why one is preferable over the other (or not). I'd like to share with you some ideas, and hopefully get some opinions back as well. Coming from the lisp side, and without much knowledge on scheme macros, I'm also trying to decide for myself whether scheme macros can have a (practical) advantage. One good point (found herehttp://lambdagrok.wikidot.com/forum/t-194636) I think explains it pretty well: lisp macros merely transform a list into another, while scheme macros use a pattern matching sub- language to apply transformations on the input syntax, and produce new syntax. I think this puts the finger on the spot. It seems to me that with macros, scheme breaks out of the homoiconicity of lisp, and opens up a new array of possibilities: define new languages with bdifferent/b syntax (while lisp allows new languages but with the same syntax). I'm saying this by looking at Racket and the direction it has chosen to go (have a look at Typed Scheme and Datalog). This looks like the world turned upside down: the pattern matching macro system is the essence of the system, and scheme is just another language defined with it. The list is not that important anymore, since it's not so essential for the macro system. Now, I have read some opinions which say that most who choose the scheme macros, make it for the pattern matching abilities and not for the hygienic part. This seems like a reasonable thing to do, since I don't hear lispers complain about unhygienicity. If there are people out there who had some practical experience with scheme macros, I hope they read this post and share some thoughts. I have a feeling that there's an additional gain with scheme macros: debugging information given by the system when something goes wrong. But it's only a feeling, I know too little of this subject to be sure. Macros are hard to debug. The stacktrace displayed by clojure does not contain information related to macro code. It's probably hard to do. My feeling relates to the fact that in scheme macro processing is not arbitrary, but rather strictly defined and under control. So I'm thinking that this gives scheme more control over what's going on in a macro and also enables scheme to give me more information in a stacktrace. I'd love to hear other opinions on this. Another point I find peculiar is the small attention that scheme macros got during all these years. I wonder why it's like that. It could be scheme's low score for practical stuff, but then again I don't know of another language that borrows these kind of macros. Does anybody know? And lastly, a question to Rich Hickey, should he read this post: what is the reasoning behind the choice of lisp macros over scheme's? Cheers, Razvan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en