# [plt-scheme] Fun with paren-shape

 From: Jens Axel Søgaard (jensaxel at soegaard.net) Date: Wed Jun 6 08:06:30 EDT 2007 Previous message: [plt-scheme] Fun with paren-shape Next message: [plt-scheme] Fun with paren-shape Messages sorted by: [date] [thread] [subject] [author]

```Andrew Reilly skrev:
> On Tue, Jun 05, 2007 at 02:32:42PM +0200, Jens Axel S??gaard wrote:
>>> [1 .. 11]
>> (1 2 3 4 5 6 7 8 9 10)
>
> I think that the idea is neat (I particularly like the
> vector-ref short-hand), but in this mode of use I think that the
> interval should go to 11, in deference with the historic use of
> [a .. b].

It's just that list and vector indices run from 0 to length-1,
which makes [0 .. (length xs)] very common.

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)

Sometimes you need the numbers in reverse, so I added:

[4 .. 1]  => '(4 3 2)
[4 ... 1] => '(4 3 2 1)

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

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

In general [count start step] produces count numbers starting

The downside is that the vector notation v[i] is now gone.

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)

[BTW: I am not convinced everything in every syntax
in this module is a good idea. Play with it,
and tell me, what's got to go]

/Jens Axel
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: concise.scm
URL: <http://lists.racket-lang.org/users/archive/attachments/20070606/a5c2864e/attachment.ksh>
```

 Posted on the users mailing list. Previous message: [plt-scheme] Fun with paren-shape Next message: [plt-scheme] Fun with paren-shape Messages sorted by: [date] [thread] [subject] [author]