Kyle R. Burton on 23 Aug 2007 13:32:19 -0000 |
> (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 -~----------~----~----~----~------~----~------~--~---
|
|