[racket] One define to rule them all

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Nov 12 21:21:24 EST 2010

Two hours ago, Neil Toronto wrote:
> In internal definition contexts, I've been using the following macro
> to define everything but functions:
> [...]

In swindle, all of these do the "obvious" things:

  (define (values a b) (values 1 2))
  (let ([(values a b) (values 1 2)]) (+ a b))
  (set! (values a b) (values b a))

and it's taking `values' as a keyword (no `match'), which means that
the usual function definition sugar works as expected.  (If you want
to define your own `values', you'd need to use an explicit lambda form
for it.)  Even more, `let' gets the same sugar:

  (let ([(plus a b) (+ a b)]) (plus 1 2))

and "of course" `set!' does the syntactic thing that the common lisp
`setf' does:

  -=> (define-struct foo (x))
  -=> (define a (make-foo 123))
  -=> (set! (foo-x a) 456)
  -=> (foo-x a)
  456

and another "of course" -- it has a `define-syntax-rule' -like form
that can define identifier macros, and the generalized `set!' expands
these so:

  -=> (defsubst b (foo-x a))
  -=> b
  456
  -=> (set! b 789)
  -=> (foo-x a)
  789


> Have I left anything out? Does anybody else think it's
> awesome/useful?  Hideous?

"Questionable".  It can be tricky to learn all the tricks if it's
taken to the above extremes.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.