Re: [racket-users] What do you use macros for?

2016-04-12 Thread Matthias Felleisen

> On Apr 12, 2016, at 4:54 PM, Anthony Carrico  wrote:
> 
>  Please view Asumu's google hangout on typed racket 


Asumu is my PhD students and the Kindergarden ought to have been a give-away 
:-) 

Yes, Racket’s syntax extension system is the second best in the world. And 
I am still young enough to take on PhD students who will improve it .. 

Want to volunteer? 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-12 Thread Anthony Carrico
On 04/11/2016 10:25 AM, Matthias Felleisen wrote:
> Second credit to Matthew (and Shriram and Robby) who kept me 
> on the 'macros are good for designing complete languages' track, 
> too. This one is important for different reasons. Often you want
> to create a reasonably complete language but not invent everything
> from scratch. In our words, you want 'linguistic inheritance'. For
> example, you like Haskell's type system but you hate, loathe, despise
> the stupid idea of universally lazy evaluation. Well, if you were
> in Racket, you'd define a 10-line language that looks, feels, smells, 
> tastes like the host but has a by-value evaluation mechanism. Of course, 
> Racket is by-value, so you may convert it into a lazy language without
> giving up the lovely parentheses and the beautiful Lisp syntax. Well, 
> it's a 10-line language definition, based on Racket's generalization
> of old, very old, stone-age old Lisp macro system. 
> 
> See the last chapter of Realm of Racket on how to teach Kindergarden 
> kids to define this kind of by-need (actually by-name) Racket. 

I love how Scheme and Racket continue to push the boundary on what can
be done with syntax extension, but these paragraphs are hyperbole. There
is a long way to go before working programmers can make linguistic
inheritance happen. At least a book needs to be written, maybe more
research. Please view Asumu's google hangout on typed racket + the class
system for evidence about just how sticky things are in the real world.
Don't get me wrong, PLT has done, and is doing the work, and that work
is under appreciated by the programming languages community, but
still... really? Let's not over-sell and under-deliver.

-- 
Anthony Carrico

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-11 Thread Matthias Felleisen

Late to the party, and to make life simple, I removed all quoted material. 

Asumu quoted me from the early 1990s. That's what I 
understood back then about macros and I got on the
wrong track with this idea for about five to eight 
years. I wanted macros to become complete language
definitions ... and that's what they are good for, 
but there is way more in all directions. So here are 
two thoughts. 

First credit to Kent Dybvig who bluntly said to me 
in '97 or so, I want to be able to define macros inside 
of some lexical scope. These days I define little macros
inside of loops or methods all the time. 

Here is an example: 

(define/public (run)
  (parameterize ([current-input-port in] [current-output-port out])
(send-message SIGN-UP)
(define ok (read-json in))
(define/fsm start
  (state: start json->start void --> choose)
  (state: choose json->choose (compose send-message values) --> 
feed-next)
  (state: feed-next json->state next->json --> feed-next || start

The above is a remote proxy that will receive three kinds of
messages on port 'in' and will respond via a call to a proper
class. Then it transitions to a different state where it will wait
for a different kind of input. The define/fsm macro makes this 
incredible easy to express. I bet everyone can read this 3-line
FSM and guess what each transition does: 

 -- in state 'feed-next', the method reads the message with json->state
 -- calls the method feed-next of the contained object 
 -- sends the result off to the 'out' port with next->json 
 -- and then transitions to either feed-next or start, 
depending on what kind of message arrives. 

The 10-line macro refers to pieces of the class and cannot be
defined globally. 

Second credit to Matthew (and Shriram and Robby) who kept me 
on the 'macros are good for designing complete languages' track, 
too. This one is important for different reasons. Often you want
to create a reasonably complete language but not invent everything
from scratch. In our words, you want 'linguistic inheritance'. For
example, you like Haskell's type system but you hate, loathe, despise
the stupid idea of universally lazy evaluation. Well, if you were
in Racket, you'd define a 10-line language that looks, feels, smells, 
tastes like the host but has a by-value evaluation mechanism. Of course, 
Racket is by-value, so you may convert it into a lazy language without
giving up the lovely parentheses and the beautiful Lisp syntax. Well, 
it's a 10-line language definition, based on Racket's generalization
of old, very old, stone-age old Lisp macro system. 

See the last chapter of Realm of Racket on how to teach Kindergarden 
kids to define this kind of by-need (actually by-name) Racket. 

In short, as Robby says 'macros' (what a stupid word) serve the whole
range of purposes, from little conveniences inside of a class to entire
language rewrites that keep the best of one language and add better
things on top 

-- Matthias







-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-08 Thread Robby Findler
I think this is not quite Matthias's point about laziness. The point
is that Haskell programmers generally (are supposed to) program as if
they don't care what order things are evaluated in, so the ability of
macros to change that order isn't relevant to them. (Of course, this
is foolish for a number of reasons -- serious Haskell programmers to
have to care what order things are evaluated in (cf seq).)

That said, I also think this thread is kind of heading down the wrong
path. This way of thinking about what is important about macros was
the best understanding we had a decade or two ago. I think that our
experience with racket, however, has proven that the right way to
think about the value of macros is to think of them as giving access
to an extensible/open compiler and thus we can more easily design and
build new programming languages. In other words, it's all about
acknowledging that there is no best language so what we really need is
the ability to more easily build new ones that fit new kinds of
computations we want to do.

Robby



On Fri, Apr 8, 2016 at 8:27 AM, Alex Knauth  wrote:
>
>> On Apr 8, 2016, at 7:10 AM, Norman Gray  wrote:
>
 I'd like to propose that there are three disciplined uses of macros:

 1. data sublanguages: I can write simple looking expressions and
 [...]

 2. binding constructs: I can introduce new binding constructs with
 [...]

 3. evaluation reordering: I can introduce constructs that delay/postpone
 [...]
   [Note: In Haskell, you don't need that one.]
>>
>> This is a seriously naive question, because I have only trivial experience 
>> with Haskell (and by extension other lazy languages), but aren't each of 
>> these things that you can do with a lazy language?
>>
>> If I can control when an expression is evaluated, then I can obviously do 
>> (3),
>
> For "evaluation reordering," it means that with macros, you could take a 
> strict language and make it lazy, *or* take a lazy language and make it 
> strict. Or you could probably do other, weirder things that I can't think of 
> right now. Haskell has forms for making specific things strict, but it's not 
> the default. Whatever the default is, you can change it with macros. So in 
> Haskell this category of macros would still exist, but `delay` wouldn't be 
> one of them. I think macros like `do` that that insert monad threading would 
> also be in this category?
>
>> but supposing I can also control the environment within which it's 
>> evaluated, can't I also do (2)
>
> In a language with static scope, no, I don't think so. In racket, haskell, 
> and most other languages, you always know at compile time what identifiers 
> are bound. You could never have an identifier that could be bound at runtime, 
> because the compiler would have seen that identifier and raised an error, at 
> compile time.
>
> It's because of this compile-time knowledge that programmers can look at a 
> program without running it, and still understand it. And also it's because of 
> this that DrRacket can look at a program without running it, but still draw 
> check-syntax arrows, or safely rename identifiers, jump to a definition, or 
> lookup documentation.
>
> Since macros that define new binding constructs are normally defined in terms 
> of existing binding constructs, the programmer still has all of this 
> knowledge at compile time, and DrRacket can still provide all those tools. 
> Because of that, both programmers and DrRacket can understand programs.
>
> If this could change at runtime, most of this would go away. But to use 
> laziness to create new binding constructs without macros, that's what you 
> would have to do.
>
> Alex Knauth

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-08 Thread Alex Knauth

> On Apr 8, 2016, at 7:10 AM, Norman Gray  wrote:

>>> I'd like to propose that there are three disciplined uses of macros:
>>> 
>>> 1. data sublanguages: I can write simple looking expressions and
>>> [...]
>>> 
>>> 2. binding constructs: I can introduce new binding constructs with
>>> [...]
>>> 
>>> 3. evaluation reordering: I can introduce constructs that delay/postpone
>>> [...]
>>>   [Note: In Haskell, you don't need that one.]
> 
> This is a seriously naive question, because I have only trivial experience 
> with Haskell (and by extension other lazy languages), but aren't each of 
> these things that you can do with a lazy language?
> 
> If I can control when an expression is evaluated, then I can obviously do (3),

For "evaluation reordering," it means that with macros, you could take a strict 
language and make it lazy, *or* take a lazy language and make it strict. Or you 
could probably do other, weirder things that I can't think of right now. 
Haskell has forms for making specific things strict, but it's not the default. 
Whatever the default is, you can change it with macros. So in Haskell this 
category of macros would still exist, but `delay` wouldn't be one of them. I 
think macros like `do` that that insert monad threading would also be in this 
category?

> but supposing I can also control the environment within which it's evaluated, 
> can't I also do (2)

In a language with static scope, no, I don't think so. In racket, haskell, and 
most other languages, you always know at compile time what identifiers are 
bound. You could never have an identifier that could be bound at runtime, 
because the compiler would have seen that identifier and raised an error, at 
compile time. 

It's because of this compile-time knowledge that programmers can look at a 
program without running it, and still understand it. And also it's because of 
this that DrRacket can look at a program without running it, but still draw 
check-syntax arrows, or safely rename identifiers, jump to a definition, or 
lookup documentation. 

Since macros that define new binding constructs are normally defined in terms 
of existing binding constructs, the programmer still has all of this knowledge 
at compile time, and DrRacket can still provide all those tools. Because of 
that, both programmers and DrRacket can understand programs.

If this could change at runtime, most of this would go away. But to use 
laziness to create new binding constructs without macros, that's what you would 
have to do.

Alex Knauth

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-08 Thread Sam Caldwell
I don't see how a lazy language would let me implement my own version of
`let`. Care to enlighten me?

- Sam Caldwell

On Fri, Apr 8, 2016 at 7:10 AM, Norman Gray  wrote:

>
> Greetings.
>
> Quoting Asumu quoting Matthias:
>
>  I'd like to propose that there are three disciplined uses of macros:
>>>
>>>  1. data sublanguages: I can write simple looking expressions and
>>> [...]
>>>
>>>  2. binding constructs: I can introduce new binding constructs with
>>> [...]
>>>
>>>  3. evaluation reordering: I can introduce constructs that delay/postpone
>>>  [...]
>>>[Note: In Haskell, you don't need that one.]
>>>
>>
> This is a seriously naive question, because I have only trivial experience
> with Haskell (and by extension other lazy languages), but aren't each of
> these things that you can do with a lazy language?
>
> If I can control when an expression is evaluated, then I can obviously do
> (3), but supposing I can also control the environment within which it's
> evaluated, can't I also do (2) and thence, with suitable juggling, go on to
> (1)?  Asumu's further example of 'use of macros that expand into submodules
> in order to provide metadata for other programs/tools' sounds at least
> complicated to do lazily, without macros, but not fundamentally impossible.
>
> Macros are obviously not the same as lazy evaluation (though from the
> point of view of the macro expander, perhaps all the post-compilation
> stages are 'lazy'), but I'm having a hard time seeing why it's obvious
> they're not isomorphic.
>
> I imagine there may be both pragmatic and fundamental semantic reasons why
> the two are different.
>
> All the best,
>
> Norman
>
>
> --
> Norman Gray  :  https://nxg.me.uk
> SUPA School of Physics and Astronomy, University of Glasgow, UK
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-08 Thread Norman Gray


Greetings.

Quoting Asumu quoting Matthias:


 I'd like to propose that there are three disciplined uses of macros:

 1. data sublanguages: I can write simple looking expressions and
[...]

 2. binding constructs: I can introduce new binding constructs with
[...]

 3. evaluation reordering: I can introduce constructs that 
delay/postpone

 [...]
   [Note: In Haskell, you don't need that one.]


This is a seriously naive question, because I have only trivial 
experience with Haskell (and by extension other lazy languages), but 
aren't each of these things that you can do with a lazy language?


If I can control when an expression is evaluated, then I can obviously 
do (3), but supposing I can also control the environment within which 
it's evaluated, can't I also do (2) and thence, with suitable juggling, 
go on to (1)?  Asumu's further example of 'use of macros that expand 
into submodules in order to provide metadata for other programs/tools' 
sounds at least complicated to do lazily, without macros, but not 
fundamentally impossible.


Macros are obviously not the same as lazy evaluation (though from the 
point of view of the macro expander, perhaps all the post-compilation 
stages are 'lazy'), but I'm having a hard time seeing why it's obvious 
they're not isomorphic.


I imagine there may be both pragmatic and fundamental semantic reasons 
why the two are different.


All the best,

Norman


--
Norman Gray  :  https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-07 Thread David Storrs
That's very cool, Dan.  Thanks for the example.  (Although, shouldn't -4^2
+ 4^2 = 32, not 31?)

If/when you do the 'further challenges' section, could you post the result
here?  It looks like it would be useful.

Dave


On Thu, Apr 7, 2016 at 1:53 PM, Daniel Prager 
wrote:

> On Thu, Apr 7, 2016 at 4:13 PM, Rickard Andersson <
> rickard.m.anders...@gmail.com> wrote:
>
>> > What have you used them for?
>>
>> https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt
>>
>> It's a macro that allows me to bundle expected inputs with expected
>> outputs for those inputs together with a contract definition, meaning
>> I have a tighter coupling of test-cases together with definitions of
>> functions without a bunch of `(module+ test ...)`.
>>
>
> That's a neat example, both as motivation for those asking "why macros?"
> and folks like me who want to get better at writing them.
>
> For a bit of learning-by-doing I was able to easily change Rickard's macro
> to get a different surface syntax that correctly processes:
>
> (define/cti (square2 x y)
>   contract:
>   (integer? integer? . -> . integer?)
>
>   tests:
>   [2 3 -> 13]
>   [1 2 -> 5]
>   [-4 4 -> 31]
>
>   implementation:
>   (+ (expt x 2) (expt y 2)))
>
> Further challenges:
>
>- allow the "contract:" and "tests:" sections to be blank, but print a
>warning
>- add handling for default, keyword and rest parameters
>
> Dan
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-07 Thread Daniel Prager
On Thu, Apr 7, 2016 at 4:13 PM, Rickard Andersson <
rickard.m.anders...@gmail.com> wrote:

> > What have you used them for?
>
> https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt
>
> It's a macro that allows me to bundle expected inputs with expected
> outputs for those inputs together with a contract definition, meaning
> I have a tighter coupling of test-cases together with definitions of
> functions without a bunch of `(module+ test ...)`.
>

That's a neat example, both as motivation for those asking "why macros?"
and folks like me who want to get better at writing them.

For a bit of learning-by-doing I was able to easily change Rickard's macro
to get a different surface syntax that correctly processes:

(define/cti (square2 x y)
  contract:
  (integer? integer? . -> . integer?)

  tests:
  [2 3 -> 13]
  [1 2 -> 5]
  [-4 4 -> 31]

  implementation:
  (+ (expt x 2) (expt y 2)))

Further challenges:

   - allow the "contract:" and "tests:" sections to be blank, but print a
   warning
   - add handling for default, keyword and rest parameters

Dan

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-07 Thread David Storrs
That makes sense.  Thank you, Rickard.

On Wed, Apr 6, 2016 at 11:13 PM, Rickard Andersson <
rickard.m.anders...@gmail.com> wrote:

> > What have you used them for?
>
> While it's certainly not the most impactful macro in the world, I was
> pretty pleased with being able to do this:
>
> https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt
>
> It's a macro that allows me to bundle expected inputs with expected
> outputs for those inputs together with a contract definition, meaning
> I have a tighter coupling of test-cases together with definitions of
> functions without a bunch of `(module+ test ...)`.
>
> > What do they do that a function couldn't?
>
> In this case we're actually generating the `(module+ test ...)` entries
> based on the lists inside the macro, but then simply appending these to
> our generated code, meaning they won't be defined in a function (which
> they can't), but rather added as if we were doing it manually.
>
> The manual variant for the first example in this file would look as
> follows:
>
> (define/contract (square x)
>   (integer? . -> . integer?)
>   (expt x 2))
>
> (module+ test
>   (check-equal? (square 2) 4)
>   (check-equal? (square 3) 9)
>   (check-equal? (square 5) 25))
>
> We're skipping straight to defining inputs and outputs, only because we
> are using macros.
>
> > What are good times to use them
>
> In this case I wanted to succinctly define test cases for functions and
> for this to be tighter coupled to function definitions, but you can't
> call `module+` while inside a function, so the only real solution is to
> lift that content outside the function definition.
>
> > ... what are their drawbacks?
>
> The obvious drawback here is that this macro is next to useless for
> anyone else when they stumble upon it. When you have an actually useful
> macro (I hesitate to call this one universally useful, though I like it
> myself), this is solved by great documentation facilities, like
> Scribble, as well as good macro constructs that will help you guide your
> user through proper usage.
>
> On Wed, Apr 06, 2016 at 05:19:05PM -0700, David Storrs wrote:
> > Hi folks,
> >
> > Macros are one of the biggest features that people list as the advantages
> > of LISP / Scheme, and I don't really understand them.  I get the basics
> --
> > they can create new code structures -- but not the implications  What
> have
> > you used them for, and what do they do that a function couldn't?  What
> are
> > good times to use them, and what are their drawbacks?
> >
> > Dave
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-07 Thread Rickard Andersson
> What have you used them for?

While it's certainly not the most impactful macro in the world, I was
pretty pleased with being able to do this:

https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt

It's a macro that allows me to bundle expected inputs with expected
outputs for those inputs together with a contract definition, meaning
I have a tighter coupling of test-cases together with definitions of
functions without a bunch of `(module+ test ...)`.

> What do they do that a function couldn't?

In this case we're actually generating the `(module+ test ...)` entries
based on the lists inside the macro, but then simply appending these to
our generated code, meaning they won't be defined in a function (which
they can't), but rather added as if we were doing it manually.

The manual variant for the first example in this file would look as
follows:

(define/contract (square x)
  (integer? . -> . integer?)
  (expt x 2))

(module+ test
  (check-equal? (square 2) 4)
  (check-equal? (square 3) 9)
  (check-equal? (square 5) 25))

We're skipping straight to defining inputs and outputs, only because we
are using macros.

> What are good times to use them

In this case I wanted to succinctly define test cases for functions and
for this to be tighter coupled to function definitions, but you can't
call `module+` while inside a function, so the only real solution is to
lift that content outside the function definition.

> ... what are their drawbacks?

The obvious drawback here is that this macro is next to useless for
anyone else when they stumble upon it. When you have an actually useful
macro (I hesitate to call this one universally useful, though I like it
myself), this is solved by great documentation facilities, like
Scribble, as well as good macro constructs that will help you guide your
user through proper usage.

On Wed, Apr 06, 2016 at 05:19:05PM -0700, David Storrs wrote:
> Hi folks,
> 
> Macros are one of the biggest features that people list as the advantages
> of LISP / Scheme, and I don't really understand them.  I get the basics --
> they can create new code structures -- but not the implications  What have
> you used them for, and what do they do that a function couldn't?  What are
> good times to use them, and what are their drawbacks?
> 
> Dave
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-06 Thread David Storrs
Nice.  Thank you, Asumu.  That helps.

On Wed, Apr 6, 2016 at 5:39 PM, Asumu Takikawa  wrote:

> Hi David,
>
> On 2016-04-06 17:19:05 -0700, David Storrs wrote:
> >Macros are one of the biggest features that people list as the
> advantages
> >of LISP / Scheme, and I don't really understand them.  I get the
> basics --
> >they can create new code structures -- but not the implications  What
> have
> >you used them for, and what do they do that a function couldn't?
> What are
> >good times to use them, and what are their drawbacks?
>
> There are three "canonical" uses of macros that people often talk about.
> The
> main reference for this idea is an e-mail by Matthias on the LL1 list:
>
>
> http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg01539.html
>
> (quoted below)
>
> At Sat, 25 May 2002 11:03:02 -0400 (EDT), Matthias Felleisen wrote:
> >  I'd like to propose that there are three disciplined uses of macros:
> >
> >  1. data sublanguages: I can write simple looking expressions and
> >  create complex nested lists/arrays/tables with quote, unquote etc
> >  neatly dressed up with macros.
> >
> >  2. binding constructs: I can introduce new binding constructs with
> >  macros. That helps me get rid of lambda's and with placing things
> >  closer together that belong together. For example, one of our teachpacks
> >  contains a form
> >(web-query ([last-name
> >  (string-append "Hello " first-name " what's your last
> name?"])
> >  ... last-name ... first-name ...)
> >  with the obvious interaction between a program and a Web consumer
> implied.
> >[Note: In ML you could write
> >   web-query(fn last-name => ...)string_append(...)
> > but by golly that's a pain and an unnecessary pattern.]
> >
> >
> >  3. evaluation reordering: I can introduce constructs that delay/postpone
> >  the evaluation of expressions as needed. Think of loops, new
> conditionals,
> >  delay/force, etc.
> >[Note: In Haskell, you don't need that one.]
> >
> >  I understand that Lispers use macros for other reasons. In all honesty,
> I
> >  believe that this is partly due to compiler deficiencies, and partly
> due to
> >  "semantic" irregularities in the target language.
> >
> >  I challenge people to address all three issues when they say language X
> >  can do what macros can do.
>
> I think Modern Racket may have additional uses for macros that don't quite
> fit
> into these. For example, the use of macros that expand into submodules in
> order
> to provide metadata for other programs/tools.
>
> Cheers,
> Asumu
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What do you use macros for?

2016-04-06 Thread Asumu Takikawa
Hi David,

On 2016-04-06 17:19:05 -0700, David Storrs wrote:
>Macros are one of the biggest features that people list as the advantages
>of LISP / Scheme, and I don't really understand them.  I get the basics --
>they can create new code structures -- but not the implications  What have
>you used them for, and what do they do that a function couldn't?  What are
>good times to use them, and what are their drawbacks?

There are three "canonical" uses of macros that people often talk about. The
main reference for this idea is an e-mail by Matthias on the LL1 list:

   http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg01539.html

(quoted below)

At Sat, 25 May 2002 11:03:02 -0400 (EDT), Matthias Felleisen wrote:
>  I'd like to propose that there are three disciplined uses of macros: 
>  
>  1. data sublanguages: I can write simple looking expressions and 
>  create complex nested lists/arrays/tables with quote, unquote etc
>  neatly dressed up with macros. 
>  
>  2. binding constructs: I can introduce new binding constructs with 
>  macros. That helps me get rid of lambda's and with placing things 
>  closer together that belong together. For example, one of our teachpacks
>  contains a form 
>(web-query ([last-name
>  (string-append "Hello " first-name " what's your last 
> name?"])
>  ... last-name ... first-name ...)
>  with the obvious interaction between a program and a Web consumer implied. 
>[Note: In ML you could write 
>   web-query(fn last-name => ...)string_append(...)
> but by golly that's a pain and an unnecessary pattern.]
>  
>  
>  3. evaluation reordering: I can introduce constructs that delay/postpone 
>  the evaluation of expressions as needed. Think of loops, new conditionals, 
>  delay/force, etc. 
>[Note: In Haskell, you don't need that one.]
>  
>  I understand that Lispers use macros for other reasons. In all honesty, I 
>  believe that this is partly due to compiler deficiencies, and partly due to 
>  "semantic" irregularities in the target language. 
>  
>  I challenge people to address all three issues when they say language X 
>  can do what macros can do.

I think Modern Racket may have additional uses for macros that don't quite fit
into these. For example, the use of macros that expand into submodules in order
to provide metadata for other programs/tools.

Cheers,
Asumu

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] What do you use macros for?

2016-04-06 Thread David Storrs
Hi folks,

Macros are one of the biggest features that people list as the advantages
of LISP / Scheme, and I don't really understand them.  I get the basics --
they can create new code structures -- but not the implications  What have
you used them for, and what do they do that a function couldn't?  What are
good times to use them, and what are their drawbacks?

Dave

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.