idea for enlighting Scheme syntax

54 views
Skip to first unread message

damien...@gmail.com

unread,
Jan 2, 2021, 6:04:35 AM1/2/21
to Racket Users
hello,

i made a few macros for scheme syntax improvments.
It uses infix Curly expressions syntax described in SRFI 105
and could be combined to use with SRFI 47 in multi dimensional arrays.

Curly expressions allows out of the box syntax more mathematicals like:

{c > t} instead of (> c t)

my macros allows more:

assignations of variables, examples:
(define x '())
 {x ← 2}
it returns 2,the value of x
{7 → x} ;; not my own idea suggested by my daughter studying python because in math we can write 7 = x in an equation but not in python :-)

{cpt <- 0}
{cpt <- {cpt + 1}}

but this would be not complete without a way to have vector and array access and assignation too:
(define T (make-vector 5))
(vector-set! T 3 7)
{T[3]}
returns 7, the value of T[3]

assignation of vector:
{T[3] <- 7}

works too with multidimensional arrays:
(define a (make-array 999 '(1 2) '(3 4)))
{a[2 4]}
returns 999

harder to code, affectaion between arrays and vectors :
{T[3] <- T[4]}
;; assign and returns the value of T[3]
'{T[3] <- T[4]}  will return :  (<- ($bracket-apply$ T 3) ($bracket-apply$ T 4))

{a[1 3] <- a[2 4]}
{a[2 4] ← 7}
{1 → a[2 4]}

those works at toplevel of REPL and in statements or block of code or body of lambda, now works too with LET end LET* and LETREC in the affectation body and in the statements part:

first a simplified LET named LOCAL as in CLOJURE Lisp that use less brackets:
(local [ x 1
            y (+ x 1)
            z (+ 2 y) ]
         z
         y)

returns 2

new special forms :

 (let-arrow* (x ← 1
                      y ← {x + 1})
             y)

returns 2

(let-arrow* [ x 1
                      y (+ x 1)
                      z (+ 2 y) ]
                  z y)

the same works with LETREC:

(letrec-arrow* [ fact ← (lambda (n)
               (if  {n = 1}
                    1
                                {n * (fact {n - 1})}))
                           ]
            (fact 5))

;; = 120



this works with Guile Scheme, the implementation of macros needs only R5RS scheme and the SRFI 105, i hope it could works a day in Racket and others Scheme implementation .

example in real code:

the code can be found here:
for LET-ARROW* and LETREC-ARROW*:

Bracket-apply overload and arrows assignations :


I wrote a little outdated page blog about that:

Racket use different schema for infix notation, one with ($ "string infix expression") and another with . (dot) such as (x . + . 1) ,they are not usable ,the latter . dot notation is a real nightmare. The best way would be to overload the READER of REPL as described in SRFI 105 Curly expressions.

Damien



damien...@gmail.com

unread,
Jan 2, 2021, 6:14:42 AM1/2/21
to Racket Users
to be complete , the form {varriable ← value} with curly brackets used in simple assignation works too in LET-ARROW*:
scheme@(guile-user)>  (let-arrow* ({x ← 1}

        {y ← {x + 1}})
        x
        y)
$2 = 2

but the simpliest form works also:
(let-arrow* (x ← 1
                     y ← {x + 1})
        x
        y)
Reply all
Reply to author
Forward
0 new messages