guile-user
[Top][All Lists]
Advanced

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

Re: Python slices in Scheme


From: Damien Mattei
Subject: Re: Python slices in Scheme
Date: Tue, 20 Jun 2023 08:41:41 +0200

hello Jay
what is Sexp Front?
regards,
Damien

On Mon, Jun 19, 2023 at 3:53 AM Jay Sulzberger <jays@panix.com> wrote:

>
> On Sun, 18 Jun 2023, Damien Mattei <damien.mattei@gmail.com> wrote:
>
> > hello,
> >
> > i'm porting the Python slicing (
> > https://docs.python.org/2/reference/expressions.html#slicings ) to
> Scheme
> > Guile and Racket.
> >
> > examples in Scheme+ :
> >
> > {#(1 2 3 4 5 6 7)[2 / 5]}
> > #(3 4 5)
>
> Damien, thank you for your work in this!
>
> Guile will be stronger when it get a serious standard array-slice
> library.
>
> For myself I would rather use
>
> (slice #(1 2 3 4 5 6 7) '(from/to 2 5))
>
> I admit that I am a member, in mostly good standing, of the Sexp Front.
>
> I deny the ridiculous accusation that the Front falls under the ban on
> oath-bound societies.  Almost all our gatherings are open to the
> public.  At such open meetings, all are welcome .  I hope that you and
> I may meet and sit down together at such a gathering.  The few
> meetings that are closed are for internal business.
>
> Again, thank you!
>
> I remain, as ever, your fellow student of history and probability,
> Jay Sulzberger
>
>
> >
> > i'm using / instead of : because : is already used by the SRFI 42 Eager
> > Comprehension
> >
> > below are my testing examples:
> >
> > ;;; compiled
> >
> /Users/mattei/.cache/guile/ccache/3.0-LE-8-4.6/usr/local/share/guile/site/3.0/Scheme+.scm.go
> >
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8)[/ / 3]}
> > $1 = #(1 4 7)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8)[/ / -2]}
> > $2 = #(8 6 4 2)
> > scheme@(guile-user)> {"elephant"[2 / 5]}
> > $3 = "eph"
> > scheme@(guile-user)> {"abcdefghijkl"[/ / -3]}
> > $4 = "lifc"
> > scheme@(guile-user)> {"123456789"[ /  / -1]}
> > $5 = "987654321"
> > scheme@(guile-user)> {"abcdefghijkl"[/ / 2]}
> > $6 = "acegik"
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ 7 / 2]}
> > $7 = #(1 3 5 7)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ 6 / -1]}
> > $8 = #(6 5 4 3 2 1)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ 6 / -2]}
> > $9 = #(6 4 2)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ -3 / -2]}
> > $10 = #(6 4 2)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[3 / / 2]}
> > $11 = #(4 6 8)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[3 / / -2]}
> > $12 = #(4 2)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-3 / / 2]}
> > $13 = #(7 9)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-3 / / -2]}
> > $14 = #(7 5 3 1)
> > scheme@(guile-user)> {"123456789"[/ -3 / -2]}
> > $15 = "642"
> > scheme@(guile-user)> {"abcdefghijklmno"[/ 7 / 2]}
> > $16 = "aceg"
> > scheme@(guile-user)> {"123456789"[/ -3 / -2]}
> > $17 = "642"
> > scheme@(guile-user)> {"abcdefghijklmno"[3 / / 2]}
> > $18 = "dfhjln"
> > scheme@(guile-user)> {"123456789"[3 /  / 2]}
> > $19 = "468"
> > scheme@(guile-user)> {"123456789"[3 /  / -2]}
> > $20 = "42"
> > scheme@(guile-user)> {"123456789"[-3 /  / -2]}
> > $21 = "7531"
> > scheme@(guile-user)> {"123456789"[-3 /  / 2]}
> > $22 = "79"
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[2 / 5 / 1]}
> > $23 = #(3 4 5)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[5 / 2 / -1]}
> > $24 = #(6 5 4)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[2 / 5 / -1]}
> > $25 = #()
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-1 / 5 / -1]}
> > $26 = #(9 8 7)
> > scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-0 / 5 / -1]}
> > $27 = #()
> > scheme@(guile-user)> {"0123456789"[5 / 2 / -1]}
> > $28 = "543"
> > scheme@(guile-user)> {"0123456789"[5 /  / -1]}
> > $29 = "543210"
> > scheme@(guile-user)> {"0123456789"[5 / 0 / -1]}
> > $30 = "54321"
> >
> > the syntax is derived from Python syntax:
> >
> > [1,2,3,4,5,6,7,8,9][-3::2]
> > [7, 9]
> > [1,2,3,4,5,6,7,8,9][-3::-2]
> > [7, 5, 3, 1]
> > [1,2,3,4,5,6,7,8,9][3::-2]
> > [4, 2]
> > "abcdefghijkl"[: : -3]
> > 'lifc'
> > [1,2,3,4,5,6,7,8,9][:5:-1]
> > [9, 8, 7]
> > [1,2,3,4,5,6,7,8,9][:5:1]
> > [1, 2, 3, 4, 5]
> > [1,2,3,4,5,6,7,8,9][0:5:-1]
> > []
> > [1,2,3,4,5,6,7,8,9][-0:5:-1]
> > []
> > [1,2,3,4,5,6,7,8,9][-1:5:-1]
> > [9, 8, 7]
> > [1,2,3,4,5,6,7,8,9][:5:-1]
> > [9, 8, 7]
> > [1,2,3,4,5,6,7,8,9][10:5:-1]
> > [9, 8, 7]
> > [1,2,3,4,5,6,7,8,9][2:5:-1]
> > []
> > [1,2,3,4,5,6,7,8,9][5:2:-1]
> > [6, 5, 4]
> > [0,1,2,3,4,5,6,7,8,9][5:2:-1]
> > [5, 4, 3]
> > [0,1,2,3,4,5,6,7,8,9][5::-1]
> > [5, 4, 3, 2, 1, 0]
> > [0,1,2,3,4,5,6,7,8,9][5:0:-1]
> > [5, 4, 3, 2, 1]
> >
> > for now it works in simple expressions,soon it will be implemented for
> > expressions with LHS and RHS like {container1[2 / 5] <- container2[7 /
> 9]}
> > for this reason all will be in the next version of Scheme+
> > https://github.com/damien-mattei/Scheme-PLUS-for-Guile
> > with other features too.
> >
> > Damien
>
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]