unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: guile-user <guile-user@gnu.org>
Subject: features of the latest release of Scheme+ (version 7.3)
Date: Thu, 18 Jan 2024 15:23:04 +0100	[thread overview]
Message-ID: <CADEOadfwuH9Q6qXOBXjja7UVVi1o4c49EctkrykzC_hEBCNBQg@mail.gmail.com> (raw)

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

Hello,

i present some features of the latest release (version 7.3) of Scheme+.

Scheme+ is an extension of the syntax of Scheme. It is 100% compatible with
the implementations of Scheme (Guile, Kawa, Racket,...).

Here are a few features:

Infix notation with operator precedence optimized by parser before
compilation for all Scheme implementation:

an infix expression like this formula (left equation - Lorentz
transformation):
[image: image.png]
can be written in Scheme+ like this:

{xp <- {x - v * t} / (sqrt {1 - v ** 2 / c ** 2})}

and is converted in a classic Scheme prefix expression with the rules of
operator precedence (before being passed to the scheme compiler or
interpreter) in:

(<- xp (/ (- x (* v t)) (sqrt (- 1 (/ (** v 2) (** c 2))))))

Assignment or definitions no more require any sort of *let *form, Scheme+
use *<- *for assignment.

Examples:

(use-modules (Scheme+))

{i <- 0}
{z[0] <- x}
{(x y) <- Lexemples[ip]}
{Ck+1 <- (replace Ck+1 'Bₖ₋₁ Bk-1-symb)}


Access to vectors,array,hash tables,string,etc with [ ] :

{z_1 <- #(1) + z[i]}
{z̃[i + 1] <- M[i] * z_1} ; z̃ = matrix * vector , return a vector

{M_i_o[j {i + 1}]  <-  M_i_o[j {i + 1}] + η * z_input[i] *
მzⳆმz̃(z_output[j] z̃_output[j]) * ᐁ_i_o[j]})

{M_i_o[j {i + 1}]  <-  M_i_o[j {i + 1}] + η * z_input[i] *
მzⳆმz̃(z_output[j] z̃_output[j]) * ᐁ_i_o[j]})


<http://hilite.me/api>
Possibility of use of neoteric expression style:
{z[i + 1] <- vector-map(activation_function_hidden_layer z̃[i + 1])}

{M <- (vector-ec (: n {lnc - 1}) ; vectors by eager comprehension (SRFI 42)
			  create-matrix-by-function(uniform-dummy nc[n + 1] {nc[n] + 1}))}
;; Matrix-vect


Definition of variable with <+ , this add a new variable in the current
envionment:
{n <+ vector-length(z)}

When needed ,declaration of variables without assigning a specific value
(in fact NIL by default):
(declare i)
(declare z z̃ M ᐁ)

*def* is a new special form for function definition it allows *return *from
the current call and recursive return with *return-rec *from all the
possibly recursive call from the defined procedure.

Example from the Guile source code itself of Scheme+:

;; split the expression between [ ] using slice as separator(def
(parse-square-brackets-arguments args-brackets)

  (when (null? args-brackets)
	(return args-brackets))

  (declare result partial-result)

  (def (psba args) ;; parse square brackets arguments


       ;;(display partial-result) (newline)
       (when (null? args)
	     {result <- (append result (!*prec partial-result))} ;; !*prec is
defined in scheme-infix.scm
	
	     (return-rec result)) ;; return from all recursive calls

       {fst <+ (car args)}

       (if (equal? slice fst)
	
	   ($>
	    (when (not (null? partial-result))
		  {result <- (append result (!*prec partial-result))} ;; evaluate
and store the expression
		  {partial-result <- '()}) ;; empty for the next possible portion
between slice operator
	    {result <- (append result (list fst))}) ;; append the slice operator
	
	   {partial-result <- (append partial-result (list fst))}) ;; not a
slice operator but append it

       (psba (cdr args))) ;; end def, recurse

  (psba args-brackets)) ;; initial call


The *repeat ... until *special form:

 (repeat

      {Ck+1-symb <+ (create-Ck-symb {k + 1})}
      ;; note: as we substitute symbol, not expressions the order has
no importance (no risk of expression containing another substitued
symbol or expression)
      {Ck+1 <- (replace Ck+1 'Cₖ Ck)} ;; substitute in Ck+1 ,Ck symbol
by his previous computation
      {Ck+1-infix <- (prefix->infix-symb Ck+1)}
      {Bk-symb <+ (create-Bk-symb k)}
      {Ck+1 <- (replace Ck+1 'Bₖ Bk-symb)}
      {Bk-1-symb <+  (create-Bk-symb {k - 1})}
      {Ck+1 <- (replace Ck+1 'Bₖ₋₁ Bk-1-symb)}

      ;; those replacements are only effective for the first steps of
loop k=0,k=1 when B0 and B-1 exists in expression of Ck+1
      {Ck+1 <- (replace Ck+1 'B₋₁ 'F)}
      {Ck+1 <- (replace Ck+1 'C₀ C0)} ;; for the anxious ones (
useless as C0 does not appear anymore after first step )
      {Ck+1 <- (replace Ck+1 'B₀ 'T)}

      {Ck+1 <- (minimal-dnf Ck+1)}
      {Ck+1-infix <- (prefix->infix-symb Ck+1)}
      (display-nl (format "~a = ~a" Ck+1-symb Ck+1-infix))
      (newline)

      {Ck <- Ck+1}
      {Ck+1 <- Ck+1-backup}
      {k <- k + 1}

      until {k >= n})


another example:


(def (product-set-with-set-imperative set1 set2)

     (when (null? set1) (return set1)) ;; empty set result
     (when (null? set2) (return set2)) ;; empty set result

     {result <+ '()}

     (repeat

      {a <+ (first set1)}
      {set1 <- (rest set1)}

      {set2-iterator <+ set2}

      (repeat

       {b <+ (first set2-iterator)}
       {set2-iterator <- (rest set2-iterator)}
       {result <- (cons (list a b) result)}

       until (null? set2-iterator))

      until (null? set1))

     result)


*for *as in C++ permits *break *and *continue*:

(for ({i <+ 0} {i < 5} {i <- i + 1})
{x <+ 7}
(display x)
(newline)
(break))

(for ({i <+ 0} {i < 5} {i <- i + 1})
 {x <+ 7}
 (continue)
 (display x)
 (newline)
 (break))

Example of Matrix multiplication implementation in Scheme+ :

(define (multiply-matrix-matrix M1 M2)

  {(n1 p1) <+ (dim-matrix-vect M1)}
  {(n2 p2) <+ (dim-matrix-vect M2)}

  (when {p1 ≠ n2} (error "matrix-by-vectors.* : matrix product
impossible, incompatible dimensions"))

  {v1 <+ (matrix-vect-v M1)}
  {v2 <+ (matrix-vect-v M2)}

  (define (res i j)
    {sum <+ 0}
    (for ({k <+ 0} {k < p1} {k <- k + 1})
    	 {sum <- sum + v1[i][k] * v2[k][j]})
    sum)

  {v <+ (create-vector-2d res n1 p2)}

  (matrix-vect v))



code example using Scheme+ for Racket,Kawa and Guile can be find also here:

https://github.com/damien-mattei/AI_Deep_Learning
https://github.com/damien-mattei/library-FunctProg/blob/296e9c7a217d59a6c1469b45cdc7353d94c0aa70/guile/logiki%2B.scm#L2532
https://github.com/damien-mattei/library-FunctProg/blob/296e9c7a217d59a6c1469b45cdc7353d94c0aa70/racket/logiki%2B.rkt#L2812
https://github.com/damien-mattei/AI_Deep_Learning/blob/2d9d080ad35cecd0471ac8f8e7e867cea205ca75/exo_retropropagationNhidden_layers_matrix_v2_by_vectors4kawa%2B.scm#L206


for now Scheme+ is available for:

Guile : https://damien-mattei.github.io/Scheme-PLUS-for-Guile/Scheme+io.html

Racket :
https://damien-mattei.github.io/Scheme-PLUS-for-Racket/Scheme+io.html

Kawa: https://github.com/damien-mattei/Scheme-PLUS-for-Kawa

Damien

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 14375 bytes --]

                 reply	other threads:[~2024-01-18 14:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADEOadfwuH9Q6qXOBXjja7UVVi1o4c49EctkrykzC_hEBCNBQg@mail.gmail.com \
    --to=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).