unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Python slices in Scheme
@ 2023-06-18 16:58 Damien Mattei
  2023-06-18 18:51 ` Dr. Arne Babenhauserheide
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Damien Mattei @ 2023-06-18 16:58 UTC (permalink / raw)
  To: guile-user

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

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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-18 16:58 Python slices in Scheme Damien Mattei
@ 2023-06-18 18:51 ` Dr. Arne Babenhauserheide
  2023-06-18 20:20   ` Damien Mattei
  2023-06-19  1:52 ` Jay Sulzberger
  2023-06-23 13:17 ` Jay Sulzberger
  2 siblings, 1 reply; 17+ messages in thread
From: Dr. Arne Babenhauserheide @ 2023-06-18 18:51 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 234 bytes --]

Hi Damien,

> {#(1 2 3 4 5 6 7)[2 / 5]}
> #(3 4 5)

that looks pretty interesting. Is it compatible to curly infix / SRFI-105?

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-18 18:51 ` Dr. Arne Babenhauserheide
@ 2023-06-18 20:20   ` Damien Mattei
  2023-06-18 21:44     ` Dr. Arne Babenhauserheide
  0 siblings, 1 reply; 17+ messages in thread
From: Damien Mattei @ 2023-06-18 20:20 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 720 bytes --]

Hello Arne,

yes it needs SRFI 105 Curly infix to allow full notation.
It defines the optional $bracket-apply$ procedure or macro (here a macro)
as described in SRFI 105. The code is in attachment (not in my github
because there is a lot of work again to have the same powerful and easy
affectation between 2 arrays than in Python)

Best regards,

Damien


On Sun, Jun 18, 2023 at 8:52 PM Dr. Arne Babenhauserheide <arne_bab@web.de>
wrote:

> Hi Damien,
>
> > {#(1 2 3 4 5 6 7)[2 / 5]}
> > #(3 4 5)
>
> that looks pretty interesting. Is it compatible to curly infix / SRFI-105?
>
> Best wishes,
> Arne
> --
> Unpolitisch sein
> heißt politisch sein,
> ohne es zu merken.
> draketo.de
>

[-- Attachment #2: apply-square-brackets.scm --]
[-- Type: application/octet-stream, Size: 22380 bytes --]

;; for guile (version compatible with my growable vector class)

;; This file is part of Scheme+

;; Copyright 2021-2023 Damien MATTEI

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.



;; SRFI 105 : Curly-infix-expressions in conjunction with specialized $bracket-apply$
;; of Scheme+ allows a syntax like {Container[index]} with vectors
;; and arrays of any dimensions,size and shape and hash tables

;; (define T (make-vector 5))
;; (vector-set! T 3 7)
;; scheme@(guile-user)> {T[3]}
;; $3 = 7
;; {T[3] <- 7}
;; 7

;; scheme@(guile-user)> (define a (make-array 999 '(1 2) '(3 4)))
;; scheme@(guile-user)> (array-ref a 2 4)
;; $3 = 999

;; scheme@(guile-user)> {a[2 4]}
;; $9 = 999

;; scheme@(guile-user)> (define b (make-array 'ho 3))
;; scheme@(guile-user)> (array-ref b 1)
;; $13 = ho

;; scheme@(guile-user)> {b[2]}
;; $15 = ho

;; scheme@(guile-user)> '{b[2]}
;; ($bracket-apply$ b 2)

;; scheme@(guile-user)> {a[2 4] <- 7}
;; scheme@(guile-user)> {a[2 4]}
;; $19 = 7
;; scheme@(guile-user)> {a[1 3] <- 5}
;; scheme@(guile-user)> {a[1 3] <- a[2 4]}
;; scheme@(guile-user)> {a[1 3]}
;; $20 = 7

;; scheme@(guile-user)> '{a[1 3] <- a[2 4]}
;; (<- ($bracket-apply$ a 1 3) ($bracket-apply$ a 2 4))



;; (define-syntax $bracket-apply$
;;   (syntax-rules ()
    
;;     ((_ container index)
;;      ;(begin ;;(display "$bracket-apply$") (newline)
;;      (cond ({(vector? container) or (growable-vector? container)} (if (equal? (quote ..) (quote index)) ;; T[1..5] Pascal syntax ;-)  
;; 								      container ;; return the vector
;; 								      (vector-ref container index))) ;; return an element of the vector
;; 	   ((hash-table? container) (hash-table-ref container index))
;; 	   ((string? container) (string-ref container index))
;; 	   (else (array-ref container index))));)
    
;;     ((_ array index1 index2 ...)
;;      ;(begin ;;(display "$bracket-apply$") (newline)
;;      (if (vector? array)
;; 	 (function-array-n-dim-ref array (reverse (list index1 index2 ...))) ;;(array-n-dim-ref array index1 index2 ...)
;; 	 (array-ref array index1 index2 ...)))));) 



(define slice /) ;;'..)

(define-syntax $bracket-apply$
  
  (syntax-rules ()


    ;; 1 argument in []
    ;; T[index]
    ((_ container index)

     ;; {#(1 2 3 4 5)[-2]}
     ;; 4
     
     (cond ((or (vector? container) (growable-vector? container))

	    (if (equal? slice index) ;; T[..] . T[1 .. 5] Pascal syntax ;-)  
		container ;; return the vector
		(if (< index 0) ;; negative index as in Python
		    (vector-ref container (+ (vector-length container) index)) ;; negative indexing
		    (vector-ref container index)))) ;; return an element of the vector
	   
	   ((hash-table? container) (hash-table-ref container index))

	   ;; sometimes i'm impress by Scheme :o
	   ;;  {"toto"[2]}
           ;; #\t
	   ;; {"toto"[-1]}
	   ;; #\o
	   ((string? container) (if (equal? slice index) ;; T[..] . T[1 .. 5] Pascal syntax ;-)  
				    container ;; return the string
				    (if (< index 0) ;; negative index as in Python
					(string-ref container (+ (string-length container) index)) ;; negative indexing
					(string-ref container index)))) ;; return an element of the string
	   
	   (else ;; array of SRFI 25	     
	    (array-ref container index)))) ;; return the element of the array
           ;; note : i do not use negative indexes or slices for array because they could be not starting at zero
    

    ;; 2 arguments in []
    ;; ex: T[i1 ..] , T[.. i2], T[i1 i2] , T[.. ..]
    ((_ container index1-or-keyword index2-or-keyword) 

     (cond ((vector? container) ;; 2 dimension vector ? or T[i1 ..] , T[.. i2]


	    ;; {#(1 2 3 4 5)[2 /]}
	    ;; '#(3 4 5)
	    ;;
	    ;; {#(1 2 3 4 5)[/ 3]}
	    ;; '#(1 2 3)
	    
	    (cond ((and (equal? slice index1-or-keyword) ;; T[.. ..]
			(equal? slice index2-or-keyword))
		   container)
		  
		  ((equal? slice index1-or-keyword) ;; T[.. i2]
		   (if (< index2-or-keyword 0) ;; negative index
		       (vector-copy container 0 (+ (vector-length container) index2-or-keyword))
		       (vector-copy container 0 index2-or-keyword)))
		  
		  ((equal? slice index2-or-keyword) ;; T[i1 ..]
		   (if (< index1-or-keyword 0) ;; negative index
		       (vector-copy container (+ (vector-length container) index1-or-keyword))
		       (vector-copy container index1-or-keyword)))
		  
		  (else ;; T[i1 i2] vector of vectors
		   (function-array-n-dim-ref container (reverse (list index1-or-keyword index2-or-keyword))))))
	   ;;(array-n-dim-ref container index1-or-keyword index2-or-keyword)


	   ;; {"hello"[/ 2]}
	   ;; "he"
	   ;; {"hello"[3 /]}
	   ;; "lo"

	   ;; {"hello"[/ /]}
	   ;; "hello"
	   ;; {"hello"[/]}
           ;; "hello"
	   ((string? container) (cond ((and (equal? slice index1-or-keyword) ;; T[/ /]
					    (equal? slice index2-or-keyword))
				       container)
				       
				       ((equal? slice index1-or-keyword) ;; T[/ i2]
					(if (< index2-or-keyword 0) ;; negative index
					    (substring container 0 (+ (string-length container) index2-or-keyword))
					    (substring container 0 index2-or-keyword)))

				       ((equal? slice index2-or-keyword) ;; T[i1 /]
					(if (< index1-or-keyword 0) ;; negative index
					    (substring container (+ (string-length container) index1-or-keyword))
					    (substring container index1-or-keyword)))
				      
				       (else ;; syntax error
					(error "$bracket-apply$ : bad arguments in string case,expecting / i2 or i1 /, provided :" index1-or-keyword index2-or-keyword) )))
	   
	   
	   (else ;; T[i1 i2] ,  2 dimension array
	    (array-ref container index1-or-keyword index2-or-keyword)))) ;; return the element of the array
            ;; note : i do not use negative indexes or slices for array because they could be not starting at zero
    

    ;; 3 arguments in []
    ;; T[i1 / i2] , T[i1 i2 i3] , T[/ / s]
    ((_ container index1-or-keyword index2-or-keyword index3-or-step) 

     ;; {#(1 2 3 4 5 6 7)[2 / 5]}
     ;; '#(3 4 5)
     (cond ((vector? container) ;; 3 dimension vector T[i1 i2 i3]? or T[i1 / i3]

	    ;; {#(1 2 3 4 5 6 7 8)[/ / 3]}
	    ;; '#(1 4 7)

	    ;; {#(1 2 3 4 5 6 7 8)[/ / -2]}
	    ;; '#(8 6 4 2)
	    (cond ((and (equal? slice index1-or-keyword) ;; T[/ / step]
			(equal? slice index2-or-keyword))

		   (when (= 0 index3-or-step)
			 (error "$bracket-apply$ : slice step cannot be zero"))
		   
		   (let* ((size-input (vector-length container))
			  (size (quotient size-input (abs index3-or-step)))
			  (result '())
			  (i 0))
		     
		     (when (not (= (modulo size-input index3-or-step) 0))
			   (set! size (+ 1 size)))
		     (set! result (make-vector size))

		     (if (< index3-or-step 0) ;; with negative index we start at end of vector (like in Python)
			 (for ((define k (- size-input 1)) (>= k 0) (set! k (+ k index3-or-step)))
			      (vector-set! result
					   i
					   (vector-ref container k))
			      (set! i (+ 1 i)))
			 (for ((define k 0) (< k size-input) (set! k (+ k index3-or-step)))
			      (vector-set! result
					   i
					   (vector-ref container k))
			      (set! i (+ 1 i))))
		     
		     result))
		  

		  ((equal? slice index2-or-keyword) ;; T[i1 / i3]
		
		   (let ((i1 index1-or-keyword)
			 (i3 index3-or-step))
		     (when (< i1 0) ;; negative index
			   (set! i1 (+ (vector-length container) i1)))
		     (when (< i3 0) ;; negative index
			   (set! i3 (+ (vector-length container) i3)))
		     (vector-copy container i1 i3)))
		
		  ;; T[i1 i2 i3] vector of vectors of vectors
		  (else (function-array-n-dim-ref container (list index3-or-step index2-or-keyword index1-or-keyword))))) ;; was reverse list ...
	          ;;or use array-n-dim-ref macro


	   
	   ;; {"elephant"[2 / 5]}
	   ;; "eph"
	   ;;  {"abcdefghijkl"[/ / 2]}
	   ;; "acegik"
	   ;; {"abcdefghijkl"[/ / -3]}
	   ;; "lifc"
	   ;; {"123456789"[ /  / -1]}
	   ;; "987654321"
	   ((string? container) ;; T[i1 / i3] or error
	    
	    (cond ((and (equal? slice index1-or-keyword) ;; T[/ / step]
			(equal? slice index2-or-keyword))

		   (when (= 0 index3-or-step)
			 (error "$bracket-apply$ : slice step cannot be zero"))
		   
		   (let* ((size-input (string-length container))
			  (size (quotient size-input (abs index3-or-step)))
			  (result '())
			  (i 0))
		     
		     (when (not (= (modulo size-input index3-or-step) 0))
			   (set! size (+ 1 size)))
		     
		     (set! result (make-string size))

		     (if (< index3-or-step 0) ;; with negative index we start at end of vector (like in Python)
			 (for ((define k (- size-input 1)) (>= k 0) (set! k (+ k index3-or-step)))
			      (string-set! result
					   i
					   (string-ref container k))
			      (set! i (+ 1 i)))
			 (for ((define k 0) (< k size-input) (set! k (+ k index3-or-step)))
			      (string-set! result
					   i
					   (string-ref container k))
			      (set! i (+ 1 i))))
		     
		     result))
		  
		  ((equal? slice index2-or-keyword) ;; T[i1 / i3]
		
		   (let ((i1 index1-or-keyword)
			 (i3 index3-or-step))
		     (when (< i1 0) ;; negative index
			   (set! i1 (+ (vector-length container) i1)))
		     (when (< i3 0) ;; negative index
			   (set! i3 (+ (vector-length container) i3)))
		     (substring container i1 i3)))

		  (else (error "$bracket-apply$ : in string case, provided too much arguments:" index1-or-keyword index2-or-keyword index3-or-step))))


	   
	   (else ;; T[i1 i2 i3] ,  3 dimension array
	    (array-ref container index1-or-keyword index2-or-keyword index3-or-step)))) ;; return the element of the array
            ;; note : i do not use negative indexes or slices for array because they could be not starting at zero
    

    ;; 4 arguments in []
    ;; T[/ i2 / s] , T[i1 / / s] , T[i1 / i3 /] , T[i1 i2 i3 i4]
    ((_ container index1-or-keyword index2-or-keyword index3-or-keyword index4-or-keyword-or-step) 
 
     (cond ((vector? container)

	    ;; {#(1 2 3 4 5 6 7 8 9)[/ 7 / 2]}
	    ;; '#(1 3 5 7)
	    ;; {#(1 2 3 4 5 6 7 8 9)[/ 6 / -1]}
	    ;; '#(6 5 4 3 2 1)
	    ;; {#(1 2 3 4 5 6 7 8 9)[/ 6 / -2]}
	    ;; '#(6 4 2)
	    ;; {#(1 2 3 4 5 6 7 8 9)[/ -3 / -2]}
	    ;; '#(6 4 2)
	    (cond ((and (equal? slice index1-or-keyword)  ;; T[/ i2 / s]
			(equal? slice index3-or-keyword))
		   
		   (when (= 0 index4-or-keyword-or-step)
			 (error "$bracket-apply$ : slice step cannot be zero"))
		    
		   (let* ((size 0) ;; result size
			  (result '())
			  (i 0)
			  (i2 index2-or-keyword))

		     (when (< i2 0) ;; negative index
			   (set! i2 (+ (vector-length container) i2)))

		     (set! size (quotient i2 (abs index4-or-keyword-or-step)))
		      
		     ;;(displayln size)
		     (when (not (= (modulo i2 index4-or-keyword-or-step) 0))
			   (set! size (+ 1 size)))
		      
		     ;;(displayln size)
		     (set! result (make-vector size))
		     
		     (if (< index4-or-keyword-or-step 0) 
			  
			 (for ((define k (- i2 1)) (>= k 0) (set! k (+ k index4-or-keyword-or-step)))
			      (vector-set! result
					   i
					   (vector-ref container k))
			      (set! i (+ 1 i)))
			  
			 (for ((define k 0) (< k i2) (set! k (+ k index4-or-keyword-or-step)))
			      (vector-set! result
					   i
					   (vector-ref container k))
			      (set! i (+ 1 i))))
		     
		     result))



		  ;; {#(1 2 3 4 5 6 7 8 9)[3 / / 2]}
		  ;; '#(4 6 8)
		  ;; > {#(1 2 3 4 5 6 7 8 9)[3 / / -2]}
		  ;; '#(4 2)
		  ;; > {#(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)
		  ((and (equal? index2-or-keyword slice)  ;; T[i1 / / s]
			(equal? index3-or-keyword slice))
		   
		    (when (= 0 index4-or-keyword-or-step)
			  (error "$bracket-apply$ : slice step cannot be zero"))
		   
		    (let* ((size-container (vector-length container))
			   (i1 (if (< index1-or-keyword 0) ;; negative index
				   (+ size-container index1-or-keyword)
				   index1-or-keyword))
			   (size-input (if (> index4-or-keyword-or-step 0)
					   (- size-container i1)
					   (+ i1 1)))
			   (size (quotient size-input (abs index4-or-keyword-or-step))) ;; result size
			   (result '())
			   (i 0))
		      
		      (when (not (= (modulo size-input index4-or-keyword-or-step) 0))
			    (set! size (+ 1 size)))
		      (set! result (make-vector size))

		      (if (< index4-or-keyword-or-step 0) 
			 
			  (for ((define k i1) (>= k 0) (set! k (+ k index4-or-keyword-or-step)))
			       (vector-set! result
					    i
					    (vector-ref container k))
			       (set! i (+ 1 i)))
			 
			  (for ((define k i1) (< k size-container) (set! k (+ k index4-or-keyword-or-step)))
			       ;;(displayln k)
			       (vector-set! result
					    i
					    (vector-ref container k))
			       (set! i (+ 1 i))))
		     
		      result))


		  ((and (equal? index2-or-keyword slice) ;; T[i1 / i3 /]
			(equal? index4-or-keyword-or-step slice))

		   (let ((i1 index1-or-keyword)
			 (i3 index3-or-keyword))
		     (when (< i1 0) ;; negative index
			   (set! i1 (+ (vector-length container) i1)))
		     (when (< i3 0) ;; negative index
			   (set! i3 (+ (vector-length container) i3)))
		     (vector-copy container i1 i3)))

		   
		   ;; T[i1 i2 i3 i4] vector of vectors of vectors ...
		   (else
		    
		    (function-array-n-dim-ref container (list index4-or-keyword-or-step index3-or-keyword index2-or-keyword index1-or-keyword))))) ;; was reverse list ...
	          ;;or use array-n-dim-ref macro

      
	   
	   ;; {"123456789"[/ -3 / -2]}
	   ;; "642"
	   ((string? container) 

	    ;; {"abcdefghijklmno"[/ 7 / 2]}
	    ;; "aceg"
	    ;; > {"123456789"[/ -3 / -2]}
	    ;; "642"
	    (cond ((and (equal? slice index1-or-keyword) ;; T[/ i2 / s]
			(equal? slice index3-or-keyword))
		   
		    (when (= 0 index4-or-keyword-or-step)
			  (error "$bracket-apply$ : slice step cannot be zero"))
		    
		    (let* ((size 0)
			   (result '())
			   (i 0)
			   (i2 index2-or-keyword))

		      (when (< i2 0) ;; negative index
			    (set! i2 (+ (string-length container) i2)))

		      (set! size (quotient i2 (abs index4-or-keyword-or-step)))
		     
		      (when (not (= (modulo i2 index4-or-keyword-or-step) 0))
			    (set! size (+ 1 size)))
		      (set! result (make-string size))

		      (if (< index4-or-keyword-or-step 0)
			 
			 (for ((define k (- i2 1)) (>= k 0) (set! k (+ k index4-or-keyword-or-step)))
			      (string-set! result
					   i
					   (string-ref container k))
			      (set! i (+ 1 i)))
			 
			 (for ((define k 0) (< k i2) (set! k (+ k index4-or-keyword-or-step)))
			      (string-set! result
					   i
					   (string-ref container k))
			      (set! i (+ 1 i))))
		     
		     result))


		  ;; {"abcdefghijklmno"[3 / / 2]}
		  ;; "dfhjln"
		  ;; > {"123456789"[3 /  / 2]}
		  ;; "468"
		  ;; > {"123456789"[3 /  / -2]}
		  ;; "42"
		  ;; > {"123456789"[-3 /  / -2]}
		  ;; "7531"
		  ;; > {"123456789"[-3 /  / 2]}
		  ;; "79"
		  ((and (equal? index2-or-keyword slice)  ;; T[i1 / / s]
			(equal? index3-or-keyword slice))
		   
		    (when (= 0 index4-or-keyword-or-step)
			  (error "$bracket-apply$ : slice step cannot be zero"))
		   
		    (let* ((size-container (string-length container))
			   (i1 (if (< index1-or-keyword 0) ;; negative index
				   (+ size-container index1-or-keyword)
				   index1-or-keyword))
			   (size-input (if (> index4-or-keyword-or-step 0)
					   (- size-container i1)
					   (+ i1 1)))
			   (size (quotient size-input (abs index4-or-keyword-or-step)))
			   (result '())
			   (i 0))
		      
		      (when (not (= (modulo size-input index4-or-keyword-or-step) 0))
			    (set! size (+ 1 size)))
		      (set! result (make-string size))

		      (if (< index4-or-keyword-or-step 0) 
			 
			  (for ((define k i1) (>= k 0) (set! k (+ k index4-or-keyword-or-step)))
			       (string-set! result
					    i
					    (string-ref container k))
			       (set! i (+ 1 i)))
			 
			  (for ((define k i1) (< k size-container) (set! k (+ k index4-or-keyword-or-step)))
			       ;;(displayln k)
			       (string-set! result
					    i
					    (string-ref container k))
			       (set! i (+ 1 i))))
		     
		      result))
	  
		 
		   ((and (equal? slice index2-or-keyword) ;; T[i1 / i3 /] 
			 (equal? slice index4-or-keyword-or-step))

		    (let ((i1  index1-or-keyword)
			  (i3 index3-or-keyword))
		      (when (< i1 0) ;; negative index
			    (set! i1 (+ (string-length container) i1)))
		      (when (< i3 0) ;; negative index
			    (set! i3 (+ (string-length container) i3)))
		      (substring container i1 i3)))

		   
		   ;; T[i1 i2 i3 i4] vector of vectors of vectors ... but we are in string context !!!
		   (else
	    
		    (error "$bracket-apply$ : in string case, provided too much arguments:" index1-or-keyword index2-or-keyword index3-or-keyword index4-or-keyword-or-step))))

	   
	   (else ;; T[i1 i2 i3 i4] ,  4 dimension array
	    (array-ref container index1-or-keyword index2-or-keyword index3-or-keyword index4-or-keyword-or-step)))) ;; return the element of the array
            ;; note : i do not use negative indexes or slices for array because they could be not starting at zero


    

    ;; 5 arguments in []
    ;; T[i1 / i3 / s] , T[i1 i2 i3 i4 i5]
    ((_ container index1 index2-or-keyword index3 index4-or-keyword index5-or-step) 

     ;; {#(1 2 3 4 5 6 7 8 9)[2 / 5 / 1]}
     ;; '#(3 4 5)
     ;; {#(1 2 3 4 5 6 7 8 9)[5 / 2 / -1]}
     ;; '#(6 5 4)
     ;; {#(1 2 3 4 5 6 7 8 9)[2 / 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)[-0 / 5 / -1]}
     ;; '#()
     (cond ((vector? container)
	    
	    (if (and (equal? index2-or-keyword slice)  ;; T[i1 / i3 / s]
		     (equal? index4-or-keyword slice))

		(begin
		   
		  (when (= 0 index5-or-step)
			(error "$bracket-apply$ : slice step cannot be zero"))
		  
		  (let* ((size-container (vector-length container))
			 
			 (i1 (if (< index1 0) ;; negative index
				 (+ size-container index1)
				 index1))

			 (i3 (if (< index3 0) ;; negative index
				 (+ size-container index3)
				 index3))
			  
			 (size-input (if (> index5-or-step 0)
					 (- i3 i1)
					 (- i1 i3)))
			  
			 (size (quotient size-input (abs index5-or-step))) ;; result size
			 (result '())
			 (i 0))
		      
		    (when (not (= (modulo size-input index5-or-step) 0))
			  (set! size (+ 1 size)))

		    (if (<= size 0)
			
			(make-vector 0)

			(begin
			  (set! result (make-vector size))
			  
			  (if (< index5-or-step 0) 
			      
			      (for ((define k i1) (> k i3) (set! k (+ k index5-or-step))) ;; we do not include i1-th element
				   ;; i do not allow Python index over size of vector
				   ;; (when (>= k size-container)
				   ;; 	 (continue))
				   
				   (vector-set! result
						i
						(vector-ref container k))
				   (set! i (+ 1 i)))
			      
			      (for ((define k i1) (< k i3) (set! k (+ k index5-or-step)))
				   ;;(displayln k)
				   (vector-set! result
						i
						(vector-ref container k))
				   (set! i (+ 1 i))))
		     
			  result))))


		;; T[i1 i2 i3 i4 i5] vector of vectors of vectors ...
		(function-array-n-dim-ref container (list index5-or-step
							  index4-or-keyword
							  index3
							  index2-or-keyword
							  index1)))) ;; was reverse list ...
                     ;;or use array-n-dim-ref macro

      
	   
	   ;; {"0123456789"[5 / 2 / -1]}
	   ;; "543"
	   ;; {"0123456789"[5 /  / -1]}
	   ;; "543210"
	   ;; {"0123456789"[5 / 0 / -1]}
	   ;; "54321"
	   ((string? container) 

	    (if (and (equal? index2-or-keyword slice)  ;; T[i1 / i3 / s]
		     (equal? index4-or-keyword slice))

		(begin
		   
		  (when (= 0 index5-or-step)
			(error "$bracket-apply$ : slice step cannot be zero"))
		  
		  (let* ((size-container (string-length container))
			 
			 (i1 (if (< index1 0) ;; negative index
				 (+ size-container index1)
				 index1))

			 (i3 (if (< index3 0) ;; negative index
				 (+ size-container index3)
				 index3))
			  
			 (size-input (if (> index5-or-step 0)
					 (- i3 i1)
					 (- i1 i3)))
			  
			 (size (quotient size-input (abs index5-or-step))) ;; result size
			 (result '())
			 (i 0))
		      
		    (when (not (= (modulo size-input index5-or-step) 0))
			  (set! size (+ 1 size)))

		    (if (<= size 0)
			
			(make-string 0)

			(begin
			  (set! result (make-string size))
			  
			  (if (< index5-or-step 0) 
			      
			      (for ((define k i1) (> k i3) (set! k (+ k index5-or-step))) ;; we do not include i1-th element
				   ;; i do not allow Python index over size of string
				   ;; (when (>= k size-container)
				   ;; 	 (continue))
				   
				   (string-set! result
						i
						(string-ref container k))
				   (set! i (+ 1 i)))
			      
			      (for ((define k i1) (< k i3) (set! k (+ k index5-or-step)))
				   ;;(displayln k)
				   (string-set! result
						i
						(string-ref container k))
				   (set! i (+ 1 i))))
		     
			  result))))

	   
		;; T[i1 i2 i3 i4 i5] vector of vectors of vectors ... but we are in string context !!!
		  
		(error "$bracket-apply$ : in string case, provided too much arguments:" index1 index2-or-keyword index3 index4-or-keyword index5-or-step)))

	   
	   (else ;; T[i1 i2 i3 i4 i5] ,  5 dimension array

	    (array-ref container index1 index2-or-keyword index3 index4-or-keyword index5-or-step)))) ;; return the element of the array
            ;; note : i do not use negative indexes or slices for array because they could be not starting at zero


    
    ;; more than 5 arguments in []
    ;; T[i1 i2 i3 i4 i5 ...]
    ((_ array index1 index2 index3 index4 index5 ...)
					
     (if (vector? array)
	 (function-array-n-dim-ref array (reverse (list index1 index2 index3 index4 index5 ...))) ;;(array-n-dim-ref array index1 index2 ...)
	 (array-ref array index1 index2 index3 index4 index5 ...)))))   ;; array SRFI 25



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-18 20:20   ` Damien Mattei
@ 2023-06-18 21:44     ` Dr. Arne Babenhauserheide
  0 siblings, 0 replies; 17+ messages in thread
From: Dr. Arne Babenhauserheide @ 2023-06-18 21:44 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 502 bytes --]


Damien Mattei <damien.mattei@gmail.com> writes:

> yes it needs SRFI 105 Curly infix to allow full notation.
> It defines the optional $bracket-apply$ procedure or macro (here a macro)
> as described in SRFI 105. The code is in attachment (not in my github
> because there is a lot of work again to have the same powerful and easy
> affectation between 2 arrays than in Python)

thank you!

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-18 16:58 Python slices in Scheme Damien Mattei
  2023-06-18 18:51 ` Dr. Arne Babenhauserheide
@ 2023-06-19  1:52 ` Jay Sulzberger
  2023-06-19 16:36   ` lloda
  2023-06-20  6:41   ` Damien Mattei
  2023-06-23 13:17 ` Jay Sulzberger
  2 siblings, 2 replies; 17+ messages in thread
From: Jay Sulzberger @ 2023-06-19  1:52 UTC (permalink / raw)
  To: guile-user; +Cc: Jay Sulzberger


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




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-19  1:52 ` Jay Sulzberger
@ 2023-06-19 16:36   ` lloda
  2023-06-19 19:44     ` Zelphir Kaltstahl
                       ` (3 more replies)
  2023-06-20  6:41   ` Damien Mattei
  1 sibling, 4 replies; 17+ messages in thread
From: lloda @ 2023-06-19 16:36 UTC (permalink / raw)
  To: Jay Sulzberger; +Cc: guile-user


My library guile-newra (1) has quite general multidimensional array slicing. The indices can be linear ranges or arbitrary integer arrays and they can have any rank. You can also use the indexed array as write target. If all the indices are linear ranges then the operation is done without copies. It also has placeholders, so you can skip axes, like :  and ... in numpy. guile-newra's arrays are applicative, so you can do (thearray firstindex secondindex ...), without special brackets.

You need wrappers to use it with Guile's native array types, so it may not be as convenient. Or maybe you don't need to handle arbitrary rank, then it might not be the best option. It's also far from finished, although the stuff I mentioned above does work.

I didn't adopt Pythons -1 = end convention because in Guile arrays can have any base index, not necessarily 0 (whether that's a good idea or not).

(1) https://lloda.github.io/guile-newra/#Slicing <https://lloda.github.io/guile-newra/#Slicing>
https://github.com/lloda/guile-newra/ <https://github.com/lloda/guile-newra/>
https://notabug.org/lloda/guile-newra <https://notabug.org/lloda/guile-newra>



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-19 16:36   ` lloda
@ 2023-06-19 19:44     ` Zelphir Kaltstahl
  2023-06-20  6:39     ` Damien Mattei
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 17+ messages in thread
From: Zelphir Kaltstahl @ 2023-06-19 19:44 UTC (permalink / raw)
  To: lloda; +Cc: guile-user

On 6/19/23 18:36, lloda wrote:
> My library guile-newra (1) has quite general multidimensional array slicing. The indices can be linear ranges or arbitrary integer arrays and they can have any rank. You can also use the indexed array as write target. If all the indices are linear ranges then the operation is done without copies. It also has placeholders, so you can skip axes, like :  and ... in numpy. guile-newra's arrays are applicative, so you can do (thearray firstindex secondindex ...), without special brackets.
>
> You need wrappers to use it with Guile's native array types, so it may not be as convenient. Or maybe you don't need to handle arbitrary rank, then it might not be the best option. It's also far from finished, although the stuff I mentioned above does work.
>
> I didn't adopt Pythons -1 = end convention because in Guile arrays can have any base index, not necessarily 0 (whether that's a good idea or not).
>
> (1)https://lloda.github.io/guile-newra/#Slicing  <https://lloda.github.io/guile-newra/#Slicing>
> https://github.com/lloda/guile-newra/  <https://github.com/lloda/guile-newra/>
> https://notabug.org/lloda/guile-newra  <https://notabug.org/lloda/guile-newra>

This reminds me of something I did for last year's advent of code: 
https://notabug.org/ZelphirKaltstahl/advent-of-code-2022/src/931399414114380121df547e6bec4dfba35772a4/day-15/array-helpers.scm

This contains notably the following functions:

(1) array-next-index: iterate through an array of arbitrary rank, going from 
index to index

(2) array-cell-ref-vec: allows partial referencing of array elements, for example:

~~~~
(array-cell-ref-vec #2((1 2 3) (4 5 6)) #(1))
=> #1(4 5 6)
(array-cell-ref-vec #3(((1 2 3) (4 5 6)) ((1 2 3) (4 5 6))) #(1))
=> #2((1 2 3) (4 5 6))
(array-cell-ref-vec #3(((1 2 3) (4 5 6)) ((1 2 3) (4 5 6))) #(1 1))
=> #1(4 5 6)
(array-cell-ref-vec #3(((1 2 3) (4 5 6)) ((1 2 3) (4 5 6))) #(1 1 1))
=> 5
~~~~

(3) array-index-of: find the index of the first element satisfying predicate 
(using array-next-index)

(4) array-indices-of: find all indices of elements satisfying a predicate (using 
array-next-index)

Regards,
Zelphir

-- 
repositories:https://notabug.org/ZelphirKaltstahl


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-19 16:36   ` lloda
  2023-06-19 19:44     ` Zelphir Kaltstahl
@ 2023-06-20  6:39     ` Damien Mattei
  2023-06-23 13:26     ` Jay Sulzberger
  2023-06-23 19:14     ` Damien Mattei
  3 siblings, 0 replies; 17+ messages in thread
From: Damien Mattei @ 2023-06-20  6:39 UTC (permalink / raw)
  To: guile-user

it seems a big work ,
thanks

On Mon, Jun 19, 2023 at 6:37 PM lloda <lloda@sarc.name> wrote:

>
> My library guile-newra (1) has quite general multidimensional array
> slicing. The indices can be linear ranges or arbitrary integer arrays and
> they can have any rank. You can also use the indexed array as write target.
> If all the indices are linear ranges then the operation is done without
> copies. It also has placeholders, so you can skip axes, like :  and ... in
> numpy. guile-newra's arrays are applicative, so you can do (thearray
> firstindex secondindex ...), without special brackets.
>
> You need wrappers to use it with Guile's native array types, so it may not
> be as convenient. Or maybe you don't need to handle arbitrary rank, then it
> might not be the best option. It's also far from finished, although the
> stuff I mentioned above does work.
>
> I didn't adopt Pythons -1 = end convention because in Guile arrays can
> have any base index, not necessarily 0 (whether that's a good idea or not).
>
> (1) https://lloda.github.io/guile-newra/#Slicing <
> https://lloda.github.io/guile-newra/#Slicing>
> https://github.com/lloda/guile-newra/ <
> https://github.com/lloda/guile-newra/>
> https://notabug.org/lloda/guile-newra <
> https://notabug.org/lloda/guile-newra>
>
>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-19  1:52 ` Jay Sulzberger
  2023-06-19 16:36   ` lloda
@ 2023-06-20  6:41   ` Damien Mattei
  2023-06-20 11:22     ` Robby Zambito
  1 sibling, 1 reply; 17+ messages in thread
From: Damien Mattei @ 2023-06-20  6:41 UTC (permalink / raw)
  To: Jay Sulzberger, guile-user

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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-20  6:41   ` Damien Mattei
@ 2023-06-20 11:22     ` Robby Zambito
  2023-06-21  7:45       ` Damien Mattei
  0 siblings, 1 reply; 17+ messages in thread
From: Robby Zambito @ 2023-06-20 11:22 UTC (permalink / raw)
  To: Damien Mattei; +Cc: Jay Sulzberger, guile-user

Jun 20, 2023 02:42:34 Damien Mattei <damien.mattei@gmail.com>:

> what is Sexp Front?

On X front is an idiom - search for "on that front" if you want to see examples.

Sexp refers to symbolic expressions, which is the typical syntax of Lisp.

Robby


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-20 11:22     ` Robby Zambito
@ 2023-06-21  7:45       ` Damien Mattei
  0 siblings, 0 replies; 17+ messages in thread
From: Damien Mattei @ 2023-06-21  7:45 UTC (permalink / raw)
  Cc: guile-user

what troubled me is the uppercase in Front and the sense and i'm not easy
with english as being french. Sexp i already know as symbolic expressions ,
that are in Scheme prefix expression but could also be infix or postfix,
SRFI 105 being an infix reader for Scheme noted with curly syntax but they
exist only at the reader stage before evaluation, only Scheme prefix
expression are evaluated being converted from infix to prefix, it can be
easily put in evidence when quoting an expression and displaying it as in
this example:
;; Racket example
'{#(1 2 3 4 5 6 7 8 9)[2 / 5 / 1]}
'($bracket-apply$ #(1 2 3 4 5 6 7 8 9) 2 / 5 / 1)

;; Guile example
scheme@(guile-user)> '{"0123456789"[5 / 2 / -1]}
$2 = ($bracket-apply$ "0123456789" 5 / 2 / -1)

note that in racket my SRFI 105 reader adaptation display the result quoted
too:'($bracket-apply$ #(1 2 3 4 5 6 7 8 9) 2 / 5 / 1)
but not of this happen in Guile, i really do not know what should be the
good result in Scheme,anyway it i think it is only a representation, it
does not change the computation when used in a program.
Damien


On Tue, Jun 20, 2023 at 1:23 PM Robby Zambito <contact@robbyzambito.me>
wrote:

> Jun 20, 2023 02:42:34 Damien Mattei <damien.mattei@gmail.com>:
>
> > what is Sexp Front?
>
> On X front is an idiom - search for "on that front" if you want to see
> examples.
>
> Sexp refers to symbolic expressions, which is the typical syntax of Lisp.
>
> Robby
>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-18 16:58 Python slices in Scheme Damien Mattei
  2023-06-18 18:51 ` Dr. Arne Babenhauserheide
  2023-06-19  1:52 ` Jay Sulzberger
@ 2023-06-23 13:17 ` Jay Sulzberger
  2023-06-24 13:08   ` Damien Mattei
  2 siblings, 1 reply; 17+ messages in thread
From: Jay Sulzberger @ 2023-06-23 13:17 UTC (permalink / raw)
  To: guile-user; +Cc: Jay Sulzberger


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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-19 16:36   ` lloda
  2023-06-19 19:44     ` Zelphir Kaltstahl
  2023-06-20  6:39     ` Damien Mattei
@ 2023-06-23 13:26     ` Jay Sulzberger
  2023-06-23 19:14     ` Damien Mattei
  3 siblings, 0 replies; 17+ messages in thread
From: Jay Sulzberger @ 2023-06-23 13:26 UTC (permalink / raw)
  To: guile-user; +Cc: Jay Sulzberger


On Mon, 19 Jun 2023, lloda <lloda@sarc.name> wrote:

> My library guile-newra (1) has quite general multidimensional array
> slicing. The indices < can be linear ranges or arbitrary integer
> arrays and they can have any rank. You can also use the indexed
> array as write target. If all the indices are linear ranges then the
> operation is done without copies. It also has placeholders, so you
> can skip axes, like : and ... in numpy. guile-newra's arrays are
> applicative, so you can do (thearray firstindex secondindex ...),
> without special brackets.

Dear lloda, I have not yet run your code, but I just now ran my eyes over

https://lloda.github.io/guile-newra/#Slicing

Heaven forwarding, I will run some of your code before the snows come.

Thank you!

oo--JS.


>
> You need wrappers to use it with Guile's native array types, so it
> may not be as convenient. Or maybe you don't need to handle
> arbitrary rank, then it might not be the best option. It's also far
> from finished, although the stuff I mentioned above does work.
>
> I didn't adopt Pythons -1 = end convention because in Guile arrays can have any
> base index, not necessarily 0 (whether that's a good idea or not).
>
> (1) https://lloda.github.io/guile-newra/#Slicing <https://lloda.github.io/guile-newra/#Slicing>
> https://github.com/lloda/guile-newra/ <https://github.com/lloda/guile-newra/>
> https://notabug.org/lloda/guile-newra <https://notabug.org/lloda/guile-newra>




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-19 16:36   ` lloda
                       ` (2 preceding siblings ...)
  2023-06-23 13:26     ` Jay Sulzberger
@ 2023-06-23 19:14     ` Damien Mattei
  3 siblings, 0 replies; 17+ messages in thread
From: Damien Mattei @ 2023-06-23 19:14 UTC (permalink / raw)
  To: guile-user

seems a great work on array Lloda , for Guile , i can not use it directly
in Scheme+ because i search portable code compatible with Racket too (and
any scheme that support SRFI 105 curly infix), but perhaps there is not a
lot of work to port it , indeed your library seems very powerful ,make me
thing of Numpy arrays in pythons.
Thanks again.
Damien

On Mon, Jun 19, 2023 at 6:37 PM lloda <lloda@sarc.name> wrote:

>
> My library guile-newra (1) has quite general multidimensional array
> slicing. The indices can be linear ranges or arbitrary integer arrays and
> they can have any rank. You can also use the indexed array as write target.
> If all the indices are linear ranges then the operation is done without
> copies. It also has placeholders, so you can skip axes, like :  and ... in
> numpy. guile-newra's arrays are applicative, so you can do (thearray
> firstindex secondindex ...), without special brackets.
>
> You need wrappers to use it with Guile's native array types, so it may not
> be as convenient. Or maybe you don't need to handle arbitrary rank, then it
> might not be the best option. It's also far from finished, although the
> stuff I mentioned above does work.
>
> I didn't adopt Pythons -1 = end convention because in Guile arrays can
> have any base index, not necessarily 0 (whether that's a good idea or not).
>
> (1) https://lloda.github.io/guile-newra/#Slicing <
> https://lloda.github.io/guile-newra/#Slicing>
> https://github.com/lloda/guile-newra/ <
> https://github.com/lloda/guile-newra/>
> https://notabug.org/lloda/guile-newra <
> https://notabug.org/lloda/guile-newra>
>
>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-23 13:17 ` Jay Sulzberger
@ 2023-06-24 13:08   ` Damien Mattei
  2023-06-24 16:18     ` Dr. Arne Babenhauserheide
  0 siblings, 1 reply; 17+ messages in thread
From: Damien Mattei @ 2023-06-24 13:08 UTC (permalink / raw)
  To: guile-user

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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-24 13:08   ` Damien Mattei
@ 2023-06-24 16:18     ` Dr. Arne Babenhauserheide
  2023-06-24 20:24       ` Damien Mattei
  0 siblings, 1 reply; 17+ messages in thread
From: Dr. Arne Babenhauserheide @ 2023-06-24 16:18 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 685 bytes --]


Damien Mattei <damien.mattei@gmail.com> writes:

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

Do you know my Zen for Scheme? In that I tried to capture what I learned
about Scheme programming in my first decade with Scheme:
https://www.draketo.de/software/zen-for-scheme

The point that applies here is:

WM:
Use the Weakest Method that gets the job done,
but know the stronger methods to employ them as needed.

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Python slices in Scheme
  2023-06-24 16:18     ` Dr. Arne Babenhauserheide
@ 2023-06-24 20:24       ` Damien Mattei
  0 siblings, 0 replies; 17+ messages in thread
From: Damien Mattei @ 2023-06-24 20:24 UTC (permalink / raw)
  To: Dr. Arne Babenhauserheide; +Cc: guile-user

hello Arne,
i already know your interesting and original web site and i read today
the zen page too.

"WM:
Use the Weakest Method that gets the job done,
but know the stronger methods to employ them as needed."

i think too it is a good philosophy to do that

Bonne journée,

Damien

On Sat, Jun 24, 2023 at 7:03 PM Dr. Arne Babenhauserheide
<arne_bab@web.de> wrote:
>
>
> Damien Mattei <damien.mattei@gmail.com> writes:
>
> > 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.
>
> Do you know my Zen for Scheme? In that I tried to capture what I learned
> about Scheme programming in my first decade with Scheme:
> https://www.draketo.de/software/zen-for-scheme
>
> The point that applies here is:
>
> WM:
> Use the Weakest Method that gets the job done,
> but know the stronger methods to employ them as needed.
>
> Best wishes,
> Arne
> --
> Unpolitisch sein
> heißt politisch sein,
> ohne es zu merken.
> draketo.de



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-06-24 20:24 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-18 16:58 Python slices in Scheme Damien Mattei
2023-06-18 18:51 ` Dr. Arne Babenhauserheide
2023-06-18 20:20   ` Damien Mattei
2023-06-18 21:44     ` Dr. Arne Babenhauserheide
2023-06-19  1:52 ` Jay Sulzberger
2023-06-19 16:36   ` lloda
2023-06-19 19:44     ` Zelphir Kaltstahl
2023-06-20  6:39     ` Damien Mattei
2023-06-23 13:26     ` Jay Sulzberger
2023-06-23 19:14     ` Damien Mattei
2023-06-20  6:41   ` Damien Mattei
2023-06-20 11:22     ` Robby Zambito
2023-06-21  7:45       ` Damien Mattei
2023-06-23 13:17 ` Jay Sulzberger
2023-06-24 13:08   ` Damien Mattei
2023-06-24 16:18     ` Dr. Arne Babenhauserheide
2023-06-24 20:24       ` Damien Mattei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).