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

how expressive are they?




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.