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" <kyle.burton@gmail.com>
  • To: philly-lambda@googlegroups.com
  • 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: mx.google.com; spf=pass (google.com: domain of kyle.burton@gmail.com designates 209.85.132.245 as permitted sender) smtp.mail=kyle.burton@gmail.com; dkim=pass (test mode) header.i=@gmail.com
  • Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; 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 philly-lambda@googlegroups.com; contact philly-lambda-owner@googlegroups.com
  • Reply-to: philly-lambda@googlegroups.com
  • Sender: philly-lambda@googlegroups.com

>  (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
it.

> 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!


Kyle

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Philly Lambda" group.
To unsubscribe from this group, send email to philly-lambda-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/philly-lambda?hl=en
-~----------~----~----~----~------~----~------~--~---