How usable are Macros, anyway? Does their use tend to produce readable code?
Is Scheme as good as Common Lisp?
1–10 of 25 posts
Re: Is Scheme as good as Common Lisp?
#2Re: Is Scheme as good as Common Lisp?
#3Use of macros makes the code reflect the programmer's thinking about the problem domain. Whether this is readable or not depends on the programmer.
Re: Is Scheme as good as Common Lisp?
#4However (a) all the Scheme implementations I know of have implemented classic defmacro macros as well, and (b) if one hadn't, you could easily write it yourself. So in practice there's not much of a decision to make.
The Arc implementation you're using to read this is written on top of Scheme. Currently Mzscheme.
Re: Is Scheme as good as Common Lisp?
#5Scheme has a way of defining macros that's supposed to be better than old-fashioned defmacro. These "hygienic macros" seemed to a lot of people (though not me) to be a good idea when they were invented. They got into the Scheme standard then. I think people don't like them so much now, but once something gets into a standard it's impossible to get it out. However (a) all the Scheme implementations I know of have impl…
Re: Is Scheme as good as Common Lisp?
#6Scheme has a way of defining macros that's supposed to be better than old-fashioned defmacro. These "hygienic macros" seemed to a lot of people (though not me) to be a good idea when they were invented. They got into the Scheme standard then. I think people don't like them so much now, but once something gets into a standard it's impossible to get it out. However (a) all the Scheme implementations I know of have impl…
What are the disadvantages? Is there any reason to dislike defining syntax rules?
Re: Is Scheme as good as Common Lisp?
#7If I didn't create a string-case= macro, I would have to write the final expression over and over again. With multiple string-case matches I would have to write string=? many many times:
(cond ((or (string=? "hello" my-string)
(string=? "world" my-string))
(print "match")))
To do that with the string-case= macro: (string-case= my-string
(("hello" "world")
(print "match")))
Saves quite a bit of typing and now I have a good example of why macros are good to have around :Dedit: formatting ftw.
Re: Is Scheme as good as Common Lisp?
#8Scheme has a way of defining macros that's supposed to be better than old-fashioned defmacro. These "hygienic macros" seemed to a lot of people (though not me) to be a good idea when they were invented. They got into the Scheme standard then. I think people don't like them so much now, but once something gets into a standard it's impossible to get it out. However (a) all the Scheme implementations I know of have impl…
Hygienic macros do seem to be a good idea: "Hygienic macros are macros whose expansion is guaranteed not to cause collisions with existing symbol definitions." (from Wikipedia, http://en.wikipedia.org/wiki/Hygienic_macro ) What are the disadvantages? Is there any reason to dislike defining syntax rules?
For me the reason is just that defmacro is easier to read.
Re: Is Scheme as good as Common Lisp?
#9Earlier quoted context omitted.
Hygienic macros do seem to be a good idea: "Hygienic macros are macros whose expansion is guaranteed not to cause collisions with existing symbol definitions." (from Wikipedia, http://en.wikipedia.org/wiki/Hygienic_macro ) What are the disadvantages? Is there any reason to dislike defining syntax rules?
One reason I've heard is that sometimes you actually want those collisions (I haven't come across a good example though - anyone know of one?). For me the reason is just that defmacro is easier to read.
(defmacro aif (test then &optional else)
`(let ((it ,test))
(if it ,then ,else)))Re: Is Scheme as good as Common Lisp?
#10Earlier quoted context omitted.
Hygienic macros do seem to be a good idea: "Hygienic macros are macros whose expansion is guaranteed not to cause collisions with existing symbol definitions." (from Wikipedia, http://en.wikipedia.org/wiki/Hygienic_macro ) What are the disadvantages? Is there any reason to dislike defining syntax rules?
One reason I've heard is that sometimes you actually want those collisions (I haven't come across a good example though - anyone know of one?). For me the reason is just that defmacro is easier to read.
(require (lib "defmacro.ss"))
(define-macro (aif a b c)
`(let ((it ,a))
(if it ,b ,c)))
(aif (* 10 10) (+ it 1) 'oops) ==> 101
The "aif" form makes it so you don't have to create a temporary variable name first -- the temp var is just assumed to be named "it". If you're thinking, "whatever, I don't need that" you are wrong. :) Somehow this turns into the most wonderful little line-saver. At my last company, we used it all over the place.