[plt-scheme] Fun with paren-shape

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Jun 6 17:32:35 EDT 2007

On Jun  6, Jens Axel Søgaard wrote:
> But - we can have both. The version below uses .. for "short"
> intervals and "..." for "long" intervals. That is:
> 
>    [1 .. 4]   => '(1 2 3)
>    [1 ... 4]  => '(1 2 3 4)

This sounds like a classic bit that is impossible to remember without
an open manual.


> Ans sometimes you need a step:
> 
>   [1 .. 7 2]   => '(1 3 5))
>   [1 .. 8 2]   => '(1 3 5 7))
>   [1 ... 7 2]  => '(1 3 5 7))
>   [1 ... 8 2]  => '(1 3 5 7))

In Swindle I used `1 3 .. 7' which makes more sense for readability,
but can be inconvenient (when you know the delta but not the first
item).  I'd go with a `step' keyword here.


> > What you've got above is more like [a .. b).  (I'm
> > pretty partial to (iota 10 1) for this particular idiom, myself,
> > though.)
> 
> Iota! Excellent idea. One could argue that (iota 5) is better
> syntax than the below, but we can always remove it. I added
> the following syntax
> 
>    [5]      =>  (iota 5)     =>  (0 1 2 3 4)
>    [5 3]    =>  (iota 5 3)   =>  (3 4 5 6 7)
>    [5 3 2]  =>  (iota 5 3 2) =>  (3 5 7 9 11)

(Ugh...)


> As a bonus I added notation for "curry" in the sense of srfi-26.
> 
>    {+ _ 3}        =>  (lambda (x) (+ x 3)
>    {+ _ (* 2 _)}  =>  (lambda (x y) (+ x (* 2 y)))
> 
> This is convenient with map and filter:
> 
>    (map {+ _ 3} [1 ... 3])  =>  '(4 5 6)

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


Posted on the users mailing list.