[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how expressive are they?



I don't know if anyone has mentioned this, but macros seem
a big win for the language designer.  Even if users weren't
allowed to get their hands on macros, it makes things 
cleaner for the designer to be able to have a small core
and build macros on top of it.  One of the explicit goals
of Arc is to do this as much as possible.

Since many of us also believe that bottom-up programming
means becoming a language designer, such advantages, if any,
thereby accrue to application programmers too.

--pg

--Avi Bryant wrote:
> 
> The argument I'm still hoping to hear is "macros are more expressive
> *than closures*", and in particular, than a lightweight lambda syntax like
> that provided by Smalltalk.  Unfortunately (like most of the posts in this
> thread) these are the wrong examples:
> 
> > How about: macros are so expressive, that Lisp doesn't
> > need primitive conditional AND and OR operators the way C has
> > && and ||.  Instead they can be macros:
> >
> > 	(OR x y)  => ((lambda (p q) (if p p (q))) x (lambda () y))
> > 	(AND x y) => ((lambda (p q) (if p (q) p)) x (lambda () y))
> 
> Smalltalk doesn't need primitives or macros:
> 
> x or: [y]
> x and: [y]
> 
> > Similarly WHEN and UNLESS are macros.  Yeah, that may seem trivial
> > to someone who hasn't worked with them, but in good Lisp code I sense
> > subtle differences of intention between
> >
> > 	(AND x y)
> > 	(IF x y)
> > 	(WHEN x y)
> 
> x and: [y]
> x ifTrue: [y]
> 
> I'm not sure about the semantics of WHEN, but other control structures
> only using blocks in Smalltalk:
> 
> [x] whileTrue
> [x] whileTrue: [y]
> [x] ifNotNil: [y]
> [x] ensure: [y]
> [x] on: SomeException do: [y]
> 
> > While these examples all do the same thing, they invite extension
> > in different directions, because
> >
> > 	(AND x y z)
> > 	(IF x y z)
> > 	(WHEN x y z)
> >
> > have rather different (and useful) behaviors.
> 
> x and: [y] and: [z]
> x ifTrue: [y] ifFalse: [z]
> 
> Now, I *know* there are better examples out there, I just want somebody to
> bring them up.  The best I can do right now is the typical with-html
> macros people use for generating markup - I've never been able to
> satisfactorily replace those in Smalltalk or Ruby.
>