Kyle R. Burton on 23 Aug 2007 13:32:19 -0000

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

[philly-lambda] Re: Do you keep wishing for the patterns from other languages?

  • From: "Kyle R. Burton" <>
  • To:
  • Subject: [philly-lambda] Re: Do you keep wishing for the patterns from other languages?
  • Date: Thu, 23 Aug 2007 09:31:53 -0400
  • Authentication-results:; spf=pass ( domain of designates as permitted sender); dkim=pass (test mode)
  • Dkim-signature: a=rsa-sha1; c=relaxed/relaxed;; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=TzeQ3lzxomYlj9GQVjZjff5aJ8RbOFLsQksq54RdrfedNkNf3NFMkRra6W2qMcYJvkRYinbC6XPuGOFu362u3e1AyXBT63MgN5bnS0F+1A9MGYsWogOO5WsPB8gfdvneoiYIPjgDPKRy1mgXTVu7RiRdnXIZ0xcefB+airH1muU=
  • Mailing-list: list; contact
  • Reply-to:
  • Sender:

>  (define-test (test-for-over-map)
> >   (let ((res (list)))
> >     (for each (key value) in-map
> >          (aprog1
> >           (java.util.HashMap.)
> >           (.put it "foo" "bar")
> >           (.put it "qux" "baz"))
> >          (set! res (cons key res)))
> >     (assert-equal res '("foo" "qux"))))
> Kyle,
> Why not just use LET?
> (let ((it (java.util.HashMap.)))
>   (.put it "foo" "bar")
>   (.put it "qux" "baz")
>   it)

That's what it the macro expands to.  It is a very small thing, but it
gives a name to the pattern, where the let expression doesn't - I like
names :)

> In your example, you're not using the result of the APROG1 expression.

The for each ... in-map uses it - it iterates over the key/value pairs
from the map.  The 'in-map' is treated as a symbol (so is the 'each')
and discarded by the syntax-rules for the for expression.  The
syntax-rules patterns use those literals in the pattern matches to
tell what I'm trying to iterate over.

I also just typed it in from memory as an example, no guarantee of
correctness :)

> I really wished that I had anaphoric IF (AIF) where, log APROG1, you
> can do stuff like this, IIRC:
> (aif (assoc people 'kyle) (cdr it) #f)
> But then I realized the COND lets me do assentially the same thing:
> (cond ((assoc people 'kyle) =>
>         (lambda (it) (cdr it)))
>       (else
>         #f))

I think I get the spirit of what you meant by that cond, but I don't
see it as equivalent to the earlier aif :)

I do see that aif, awhen, aprog1 and others are very thin wrappers
around if/when/let - they only factor out a tiny little bit - but when
I see forms using those names I find it easier to know what is going
on - I can more immediately know what the code is doing - prog1 is an
expression/initializer and some side effects (but not on the
initialized thing), aprog1 is an initializer plus some side effects
where the side effects are applied to the thing to be returned.  I
hold a different concept for let in my head when I see code that uses

> As for the main point of your message: Yes, absolutely! I've come to
> see Javascript as the nicest language with C-like syntax, because I
> can use closures and first-class anonymous functions everywhere.
> Writing Ajax apps almost requires that you think in terms of CPS
> (continuation passing style).

That's a good way of thinking about it!


You received this message because you are subscribed to the Google Groups "Philly Lambda" group.
To unsubscribe from this group, send email to
For more options, visit this group at