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: Sat, 24 Jun 2023 15:08:15 +0200

hello Jay,

for code testing i think in this summer, when i will have updated a new
release of Scheme+ , i will show two codes to compare , one in Python
(already written) and the other in Scheme/Scheme+ (to finish...) doing the
same thing (Deep Learning - backpropagation and gradient descent) to
compare codes line by line presented on a web page. I'm not doing that
for proselytizing
but to compare honestly, i'm not for/against scheme/python , i just like
comparing languages, in the past i was against Python but now i thin it is
really easy and powerful, but i dislike decorator, i prefer scheme's macro
but i think too it has no sense to write big macros, in my opinion they
should be short and avoid them when possible.

Regards,


On Fri, Jun 23, 2023 at 3:18 PM 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)
> >
> > i'm using / instead of : because : is already used by the SRFI 42 Eager
> > Comprehension
>
> Damien, I just now looked, but have not yet read carefully, the
> Scheme+ manifesto.
>
> Heaven forwarding, I will try some of the code before the snows come.
>
> Thank you!
>
> oo--JS.
>
>
> >
> > 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]