Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days- macros
Also very interesting is eli's http://blog.racket-lang.org/2008/02/dirty-looking-hygiene.html Teaches how to ittify with syntax-rules and syntax-parameterize. Jos _ From: [email protected] [mailto:[email protected]] On Behalf Of Stephen De Gabrielle Sent: 05 April 2011 11:10 To: users Subject: Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days- macros In case any lurkers like me are interested. http://blog.racket-lang.org/2011/04/writing-syntax-case-macros.html Stephen On Tue, Apr 5, 2011 at 12:51 AM, Robby Findler wrote: On Mon, Apr 4, 2011 at 6:25 PM, Eli Barzilay wrote: > Four hours ago, Robby Findler wrote: >> >> It looks like a great macro essay for a certain crowd (altho the >> essay seems to insult that selfsame crowd; perhaps you are assuming >> that that crowd is into S&M?). > > Where's the insult? (I didn't mean any insult -- the only thing I can > think of is the "nostalgia" reference, which is not an insult but the > often expressed sentiment for "a simple system, like `defmacro'".) Well, the scare quotes are a way to put down things, generally speaking. > >> Some comments: >> >> - I probably would have used #` in the second while macro. Yes, I >> see you mention it later, but doing it at that point seems to fit >> with what the reader's been given at that point > > Well, that's one point where the purpose of the document is different > from a generic guide: my main goal was to write a quick intro to > people who are familiar with `defmacro' -- so I wanted to make it very > clear that it's the same kind of thing, only with wrapped sexprs > instead of raw ones. In this case, I think that the long route is > better -- it shows that the extra tools (like #`) make things easier > only after you're aware of what goes on (and the fact that there's no > complicated magic involved, which is the frequent complain against > `syntax-case'). Yes, and the second while macro is a fine place to say that, in my opinion. Indeed, it seems like the most natural point to go to next and then to continue later to say what is happening with the # on the front. This is just how your text is already building (in a good way imo). > >> - it would be good if you did some kind of a computation at compile >> time, preferably to demonstrate an interesting computation one >> should want to do at compile time. Maybe a macro that embeds a >> formatted source location into its output? > > Good idea, I'll add something. > > >> - cpp macros are, I believe, based on lexemes, not strings (so you >> cannot have an unclosed string in a macro or something). > > Yeah, I couldn't find a way to phrase it better than stick a random > "roughly" in. Using "lexemes" is a good word to describe it, but it's > a little too opaque -- any ideas for something more light? "lexical tokens, like strings, parens, ..."? > >> At least nowadays they are. > > Yes -- I definitely have used `#define's with a double-quote opener. I think you can still pass an arg to gcc to get the old behavior back. Robby _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
In case any lurkers like me are interested. http://blog.racket-lang.org/2011/04/writing-syntax-case-macros.html Stephen On Tue, Apr 5, 2011 at 12:51 AM, Robby Findler wrote: > On Mon, Apr 4, 2011 at 6:25 PM, Eli Barzilay wrote: > > Four hours ago, Robby Findler wrote: > >> > >> It looks like a great macro essay for a certain crowd (altho the > >> essay seems to insult that selfsame crowd; perhaps you are assuming > >> that that crowd is into S&M?). > > > > Where's the insult? (I didn't mean any insult -- the only thing I can > > think of is the "nostalgia" reference, which is not an insult but the > > often expressed sentiment for "a simple system, like `defmacro'".) > > Well, the scare quotes are a way to put down things, generally speaking. > > > > >> Some comments: > >> > >> - I probably would have used #` in the second while macro. Yes, I > >> see you mention it later, but doing it at that point seems to fit > >> with what the reader's been given at that point > > > > Well, that's one point where the purpose of the document is different > > from a generic guide: my main goal was to write a quick intro to > > people who are familiar with `defmacro' -- so I wanted to make it very > > clear that it's the same kind of thing, only with wrapped sexprs > > instead of raw ones. In this case, I think that the long route is > > better -- it shows that the extra tools (like #`) make things easier > > only after you're aware of what goes on (and the fact that there's no > > complicated magic involved, which is the frequent complain against > > `syntax-case'). > > Yes, and the second while macro is a fine place to say that, in my > opinion. Indeed, it seems like the most natural point to go to next > and then to continue later to say what is happening with the # on the > front. This is just how your text is already building (in a good way > imo). > > > > >> - it would be good if you did some kind of a computation at compile > >> time, preferably to demonstrate an interesting computation one > >> should want to do at compile time. Maybe a macro that embeds a > >> formatted source location into its output? > > > > Good idea, I'll add something. > > > > > >> - cpp macros are, I believe, based on lexemes, not strings (so you > >> cannot have an unclosed string in a macro or something). > > > > Yeah, I couldn't find a way to phrase it better than stick a random > > "roughly" in. Using "lexemes" is a good word to describe it, but it's > > a little too opaque -- any ideas for something more light? > > "lexical tokens, like strings, parens, ..."? > > > > >> At least nowadays they are. > > > > Yes -- I definitely have used `#define's with a double-quote opener. > > I think you can still pass an arg to gcc to get the old behavior back. > > Robby > > _ > For list-related administrative tasks: > http://lists.racket-lang.org/listinfo/users > _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Mon, Apr 4, 2011 at 6:25 PM, Eli Barzilay wrote: > Four hours ago, Robby Findler wrote: >> >> It looks like a great macro essay for a certain crowd (altho the >> essay seems to insult that selfsame crowd; perhaps you are assuming >> that that crowd is into S&M?). > > Where's the insult? (I didn't mean any insult -- the only thing I can > think of is the "nostalgia" reference, which is not an insult but the > often expressed sentiment for "a simple system, like `defmacro'".) Well, the scare quotes are a way to put down things, generally speaking. > >> Some comments: >> >> - I probably would have used #` in the second while macro. Yes, I >> see you mention it later, but doing it at that point seems to fit >> with what the reader's been given at that point > > Well, that's one point where the purpose of the document is different > from a generic guide: my main goal was to write a quick intro to > people who are familiar with `defmacro' -- so I wanted to make it very > clear that it's the same kind of thing, only with wrapped sexprs > instead of raw ones. In this case, I think that the long route is > better -- it shows that the extra tools (like #`) make things easier > only after you're aware of what goes on (and the fact that there's no > complicated magic involved, which is the frequent complain against > `syntax-case'). Yes, and the second while macro is a fine place to say that, in my opinion. Indeed, it seems like the most natural point to go to next and then to continue later to say what is happening with the # on the front. This is just how your text is already building (in a good way imo). > >> - it would be good if you did some kind of a computation at compile >> time, preferably to demonstrate an interesting computation one >> should want to do at compile time. Maybe a macro that embeds a >> formatted source location into its output? > > Good idea, I'll add something. > > >> - cpp macros are, I believe, based on lexemes, not strings (so you >> cannot have an unclosed string in a macro or something). > > Yeah, I couldn't find a way to phrase it better than stick a random > "roughly" in. Using "lexemes" is a good word to describe it, but it's > a little too opaque -- any ideas for something more light? "lexical tokens, like strings, parens, ..."? > >> At least nowadays they are. > > Yes -- I definitely have used `#define's with a double-quote opener. I think you can still pass an arg to gcc to get the old behavior back. Robby _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
Four hours ago, Robby Findler wrote: > > It looks like a great macro essay for a certain crowd (altho the > essay seems to insult that selfsame crowd; perhaps you are assuming > that that crowd is into S&M?). Where's the insult? (I didn't mean any insult -- the only thing I can think of is the "nostalgia" reference, which is not an insult but the often expressed sentiment for "a simple system, like `defmacro'".) > Some comments: > > - I probably would have used #` in the second while macro. Yes, I > see you mention it later, but doing it at that point seems to fit > with what the reader's been given at that point Well, that's one point where the purpose of the document is different from a generic guide: my main goal was to write a quick intro to people who are familiar with `defmacro' -- so I wanted to make it very clear that it's the same kind of thing, only with wrapped sexprs instead of raw ones. In this case, I think that the long route is better -- it shows that the extra tools (like #`) make things easier only after you're aware of what goes on (and the fact that there's no complicated magic involved, which is the frequent complain against `syntax-case'). > - it would be good if you did some kind of a computation at compile > time, preferably to demonstrate an interesting computation one > should want to do at compile time. Maybe a macro that embeds a > formatted source location into its output? Good idea, I'll add something. > - cpp macros are, I believe, based on lexemes, not strings (so you > cannot have an unclosed string in a macro or something). Yeah, I couldn't find a way to phrase it better than stick a random "roughly" in. Using "lexemes" is a good word to describe it, but it's a little too opaque -- any ideas for something more light? > At least nowadays they are. Yes -- I definitely have used `#define's with a double-quote opener. -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Mon, Apr 4, 2011 at 1:27 PM, Eli Barzilay wrote: > 6 hours ago, Sam Tobin-Hochstadt wrote: >> >> Eli wrote an excellent introduction to Racket macros on >> comp.lang.scheme recently, which I've encouraged him to post on the >> Racket blog. > > I'm not sure how "excellent" it is, but I posted it now. Please let > me know if you see any obvious problems. It looks like a great macro essay for a certain crowd (altho the essay seems to insult that selfsame crowd; perhaps you are assuming that that crowd is into S&M?). Some comments: - I probably would have used #` in the second while macro. Yes, I see you mention it later, but doing it at that point seems to fit with what the reader's been given at that point - it would be good if you did some kind of a computation at compile time, preferably to demonstrate an interesting computation one should want to do at compile time. Maybe a macro that embeds a formatted source location into its output? - cpp macros are, I believe, based on lexemes, not strings (so you cannot have an unclosed string in a macro or something). At least nowadays they are. Robby _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
6 hours ago, Sam Tobin-Hochstadt wrote: > > Eli wrote an excellent introduction to Racket macros on > comp.lang.scheme recently, which I've encouraged him to post on the > Racket blog. I'm not sure how "excellent" it is, but I posted it now. Please let me know if you see any obvious problems. (BTW, does anyone know why different parts of the text get different line spacing?) -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Mon, Apr 4, 2011 at 8:13 AM, Matthias Felleisen wrote: > > On Apr 4, 2011, at 5:45 AM, Archie Maskill wrote: > > On Wed, Mar 30, 2011 at 11:29 AM, John Sampson wrote: >> >> Do you think these give a better explanation of macros? On the whole, I >> have found Teach Yourself Scheme >> relatively easy to follow. >> >> Regards >> >> _John Sampson_ > > I was learning how to use scheme macros recently, and I found this document > extremely useful: > > http://www.xs4all.nl/~hipster/lib/scheme/gauche/define-syntax-primer.txt > > I'm not sure how much adaptation (if any) it would require to work with > Racket. Hope it's some use to you, too! > > > Joe's essay is a decent start for syntax-rules, the macro system from the > 1990s. > I am sure Ryan should and could write something equally useful for what > Racket offers above and beyond syntax-rules. Eli wrote an excellent introduction to Racket macros on comp.lang.scheme recently, which I've encouraged him to post on the Racket blog. -- sam th [email protected] _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Apr 4, 2011, at 5:45 AM, Archie Maskill wrote: > On Wed, Mar 30, 2011 at 11:29 AM, John Sampson wrote: > Do you think these give a better explanation of macros? On the whole, I have > found Teach Yourself Scheme > relatively easy to follow. > > Regards > > _John Sampson_ > > I was learning how to use scheme macros recently, and I found this document > extremely useful: > > http://www.xs4all.nl/~hipster/lib/scheme/gauche/define-syntax-primer.txt > > I'm not sure how much adaptation (if any) it would require to work with > Racket. Hope it's some use to you, too! Joe's essay is a decent start for syntax-rules, the macro system from the 1990s. I am sure Ryan should and could write something equally useful for what Racket offers above and beyond syntax-rules. -- Matthias _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Wed, Mar 30, 2011 at 11:29 AM, John Sampson wrote: > Do you think these give a better explanation of macros? On the whole, I > have found Teach Yourself Scheme > relatively easy to follow. > > Regards > > _John Sampson_ I was learning how to use scheme macros recently, and I found this document extremely useful: http://www.xs4all.nl/~hipster/lib/scheme/gauche/define-syntax-primer.txt I'm not sure how much adaptation (if any) it would require to work with Racket. Hope it's some use to you, too! Regards, -- Archie Maskill _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
Yes, go ahead! regards, --dorai On Wed, Mar 30, 2011 at 12:00 PM, Matthias Felleisen wrote: > > On Mar 30, 2011, at 11:20 AM, Prabhakar Ragde wrote: > > > Matthias wrote: > > > Do you think these give a better explanation of macros? On the > whole, I have found Teach Yourself Scheme relatively easy to > follow. > >> Yes, but when it comes to macros, it espouses a view that was never > >> compatible with any Report on Scheme and is even old-school for plain > >> Lisp. If you care about Scheme per se, see Dybvig's book. If you wish > >> to study the most powerful macro technology in the world, study the > >> Guide. -- Matthias > > > > This comment is about more than macros: Since students are often drawn to > TYS even though I never mention it to them, I've always been tempted to > "translate" TYS into what is now Racket, not just literally but with some of > the HtDP philosophy infused. While I think the Guide is great, as are HtDP > and HtDP/2e, I wonder if there is some value in a document of the length of > TYS, and whether TYS can serve as a model. --PR > > Go ahead. I am sure Dorai won't mind. Dorai? > > _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Wed, Mar 30, 2011 at 12:23 PM, Matthew Flatt wrote: > At Wed, 30 Mar 2011 11:20:30 -0400, Prabhakar Ragde wrote: >> This comment is about more than macros: Since students are often drawn >> to TYS even though I never mention it to them, I've always been tempted >> to "translate" TYS into what is now Racket, not just literally but with >> some of the HtDP philosophy infused. While I think the Guide is great, >> as are HtDP and HtDP/2e, I wonder if there is some value in a document >> of the length of TYS, and whether TYS can serve as a model. > > Yes, absolutely. We need lots of documents that say the same thing in > different and better ways. The TYS length has worked very well for other languages; two examples are "_why's poignant guide to ruby", and "learn you a haskell for great good". One other good idea is to release chapters as you go, rather than waiting until it's all finished. -- sam th [email protected] _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
At Wed, 30 Mar 2011 11:20:30 -0400, Prabhakar Ragde wrote: > This comment is about more than macros: Since students are often drawn > to TYS even though I never mention it to them, I've always been tempted > to "translate" TYS into what is now Racket, not just literally but with > some of the HtDP philosophy infused. While I think the Guide is great, > as are HtDP and HtDP/2e, I wonder if there is some value in a document > of the length of TYS, and whether TYS can serve as a model. Yes, absolutely. We need lots of documents that say the same thing in different and better ways. _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Mar 30, 2011, at 11:20 AM, Prabhakar Ragde wrote: > Matthias wrote: > Do you think these give a better explanation of macros? On the whole, I have found Teach Yourself Scheme relatively easy to follow. >> Yes, but when it comes to macros, it espouses a view that was never >> compatible with any Report on Scheme and is even old-school for plain >> Lisp. If you care about Scheme per se, see Dybvig's book. If you wish >> to study the most powerful macro technology in the world, study the >> Guide. -- Matthias > > This comment is about more than macros: Since students are often drawn to TYS > even though I never mention it to them, I've always been tempted to > "translate" TYS into what is now Racket, not just literally but with some of > the HtDP philosophy infused. While I think the Guide is great, as are HtDP > and HtDP/2e, I wonder if there is some value in a document of the length of > TYS, and whether TYS can serve as a model. --PR Go ahead. I am sure Dorai won't mind. Dorai? _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
Matthias wrote: Do you think these give a better explanation of macros? On the whole, I have found Teach Yourself Scheme relatively easy to follow. Yes, but when it comes to macros, it espouses a view that was never compatible with any Report on Scheme and is even old-school for plain Lisp. If you care about Scheme per se, see Dybvig's book. If you wish to study the most powerful macro technology in the world, study the Guide. -- Matthias This comment is about more than macros: Since students are often drawn to TYS even though I never mention it to them, I've always been tempted to "translate" TYS into what is now Racket, not just literally but with some of the HtDP philosophy infused. While I think the Guide is great, as are HtDP and HtDP/2e, I wonder if there is some value in a document of the length of TYS, and whether TYS can serve as a model. --PR _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Mar 30, 2011, at 6:29 AM, John Sampson wrote: > Do you think these give a better explanation of macros? On the whole, I have > found Teach Yourself Scheme > relatively easy to follow. Yes, but when it comes to macros, it espouses a view that was never compatible with any Report on Scheme and is even old-school for plain Lisp. If you care about Scheme per se, see Dybvig's book. If you wish to study the most powerful macro technology in the world, study the Guide. -- Matthias _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
2011/3/30 John Sampson : > Hello - > > I am going through TYSIFD which is said to be compatible with mzScheme. > > Descriptions of macros seem to be different depending which book one reads. > TYSIFD advises the reader to 'require' the defmacro library > - '(require (lib "defmacro.rkt"))' when using Racket (I assume) - and gives > the example > > (define-macro when > (lambda (test .branch) > (list 'if test > (cons 'begin branch Way back in the olden days define-macro was a popular way to define macros. Back then define-syntax had not yet been invented. TYSIFD is slightly old so when it was written it made sense to use define-macro. Today I am sure the author would have chosen define-syntax. Now it ought to be possible to get the programs in the macro section running in MzScheme, since it is reasonable straightforward to write define-macro in terms of define-syntax. That is, the incantation (require (lib "defmacro.rkt")) makes define-macro available to you. But macros written with the help of define-macro is integrated as well as define-syntax in DrScheme/DrRacket. To make a long story short: Skip the macro section in TYSIFD (it is simply too old) and read the racket guide on macros. -- Jens Axel Søgaard _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Wed, Mar 30, 2011 at 11:31, John Sampson wrote: > Hello - > > I am going through TYSIFD which is said to be compatible with mzScheme. > > Descriptions of macros seem to be different depending which book one reads. > TYSIFD advises the reader to 'require' the defmacro library > - '(require (lib "defmacro.rkt"))' when using Racket (I assume) - and gives > the example > > (define-macro when > (lambda (test .branch) >(list 'if test > (cons 'begin branch btw, try substituting the last two lines with: (list 'if test (cons 'begin branch) #f))) the problem is that if's in racket must have both arms, while in other dialects they can be one-armed. Cheers P. _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Wed, Mar 30, 2011 at 12:29, John Sampson wrote: > Do you think these give a better explanation of macros? On the whole, I have > found Teach Yourself Scheme > relatively easy to follow. I read TYSIFD many years ago and I don't remember exactly what it says about macros. >From your first post I see that it talks (only? I don't remember) about non hygienic macros, which is what we had many years ago. You can start learning about the current state of the art in macros from the Help Desk, or from TSPL: http://www.scheme.com/tspl4/ Cheers P. _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users
Re: [racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros
On Wed, Mar 30, 2011 at 11:31, John Sampson wrote: > What is the best source for learning about macros in Racket, assuming no > previous > knowledge of macros? Have you already tried the Getting Started docs in the Help Desk? _ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users

