i have this macro i just modified:
;; "abcdefgh"
;; > {s[2 * 3 - 4 $ 2 * 3 + 1 $ 2 * 4 - 6] <- "0000"}
;; "ab0d0f0h"
;; $bracket-apply$ is from SRFI 105 bracket-apply is an argument of the macro
(define-syntax <-
(syntax-rules ()
((_ (kar kdr) expr) ; expr must be a pair
(begin
(set! kar (car expr))
(set! kdr (cdr expr))))
;; special form like : (<- ($bracket-apply$ T 3) ($bracket-apply$ T 4))
;; We will let the second $bracket-apply$ be executed and forbid the execution of first $bracket-apply$.
;; one dimension array, example: {a[4] <- 7}
;; $bracket-apply$ is from SRFI 105 bracket-apply is an argument of the macro
((_ (bracket-apply container index ...) expr)
(begin
;; add a checking
;; (define x 3)
;; > (<- (aye x 3) 7)
;; . . ../Scheme-PLUS-for-Racket/main/Scheme-PLUS-for-Racket/required-files/assignment.rkt:1:6: Bad <- form: the LHS of expression must be an identifier or of the form ($bracket-apply$ container index) , first argument 'aye " is not $bracket-apply$."
(unless (equal? (quote $bracket-apply$) (quote bracket-apply))
(error "Bad <- form: the LHS of expression must be an identifier or of the form ($bracket-apply$ container index ...) , first argument is not $bracket-apply$:"
(quote bracket-apply)))
(parse-square-brackets-arguments-and-assignment container expr index ...)))
;;(<- x 5)
((_ var expr)
(begin
;;(display "<- : variable set!") (newline)
(set! var expr)
var))
;; (declare x y z t)
;; {x <- y <- z <- t <- 7}
;; 7
;; (list x y z t)
;; (7 7 7 7)
;; > (require srfi/25)
;; > {I <- (make-array (shape 0 4 0 4))}
;; #<array:srfi-9-record-type-descriptor>
;; > {I[0 0] <- I[1 1] <- I[2 2] <- I[3 3] <- 1}
;; 1
;; > {I[0 0]}
;; 1
;; > {I[0 1]}
;; 0
;; > I
;; #<array:srfi-9-record-type-descriptor>
((_ var var1 ... expr)
(<- var (<- var1 ... expr)))
))
i just added the first case:
((_ (kar kdr) expr) ; expr must be a pair
(begin
(set! kar (car expr))
(set! kdr (cdr expr))))
and it works but my idea was that the place of this case could be in second position as there is no possible confusion ,the number of args in the first nested expression in parenthesis being not the same: (kar kdr) versus (bracket-apply container index ...)
but in fact no , if i do that it fails:
(declare a b)
{(a b) <- (cons 7 8)}
In procedure raise-exception:
Bad <- form: the LHS of expression must be an identifier or of the form ($bracket-apply$ container index ...) , first argument is not $bracket-apply$: a
good evaluation:
> (declare a b)
> '{(a b) <- (cons 7 8)}
'(<- (a b) (cons 7 8))
> {(a b) <- (cons 7 8)}
> a
7
> b
8