From a773c85f52057c72aac700da3b3ddd11397acd2a Mon Sep 17 00:00:00 2001 From: Damien MATTEI Date: Wed, 22 Nov 2023 21:43:29 +0100 Subject: [PATCH] guile --- Scheme+.scm | 147 ++++++++++++++++++++++---------- array.scm | 52 +++++++++--- first-and-rest.scm | 17 ++-- for_next_step.scm | 83 +++++++++++++++++- increment.scm | 5 ++ infix-operators.scm | 66 ++++++++++++++ list.scm | 203 ++++++++++++++++++++++++++++++++++++++++++++ overload.scm | 79 +++++++++-------- scheme-infix.scm | 47 +--------- 9 files changed, 550 insertions(+), 149 deletions(-) create mode 100644 infix-operators.scm create mode 100644 list.scm diff --git a/Scheme+.scm b/Scheme+.scm index a278908..62416fe 100644 --- a/Scheme+.scm +++ b/Scheme+.scm @@ -1,6 +1,6 @@ ;; Scheme+.scm -;; version 7.1 +;; version 7.2 ;; author: Damien MATTEI @@ -35,57 +35,110 @@ ;; install linux: ;; sudo cp *.scm /usr/share/guile/site/3.0 +(define-module (Scheme+) -(use-modules (growable-vector) - (overload) + #:use-module (for_next_step) + #:use-module (growable-vector) ;;#:use-module (ice-9 local-eval) - (ice-9 match) - (ice-9 arrays) ;; for array-copy - (srfi srfi-1) ;; any,every - (srfi srfi-69) ;; Basic hash tables - (srfi srfi-31) ;; rec - (srfi srfi-26) ;; cut + #:use-module (infix-operators) + #:use-module (overload) + #:use-module (array) + #:use-module (ice-9 match) + #:use-module (ice-9 arrays) ;; for array-copy + #:use-module (srfi srfi-1) ;; any,every + #:use-module (srfi srfi-69) ;; Basic hash tables + #:use-module (srfi srfi-31) ;; rec + #:use-module (srfi srfi-26) ;; cut ;;#:use-module (srfi srfi-43) ;; WARNING: (Scheme+): `vector-copy' imported from both (growable-vector) and (srfi srfi-43) - ) - ;; use with scheme-infix.scm included from module (caveit with overloading) - ;; or with scheme-infix.scm included in main not module (ok) + ;;#:use-module (apply-square-brackets) - - - -(include "def.scm") -;;(include "array.scm") ;; MUST be included after assignment ..... -(include "set-values-plus.scm") - -(include "for_next_step.scm") ;; for apply-square-brackets.scm, assignment.scm -;; if you want it at toplevel: (include "for_next_step.scm") or add some export in this file.... - - -(include "declare.scm") -(include "condx.scm") -(include "block.scm") -(include "not-equal.scm") -(include "exponential.scm") -(include "while-do-when-unless.scm") -(include "repeat-until.scm") -(include "modulo.scm") -(include "bitwise.scm") - - - -;; must be included from program file now ! (use "scheme-infix.scm" in included-files of scheme+ directory) - - - -;;(include "scheme-infix-define-macro.scm") - - - - -(include "slice.scm") - - + ;; use with scheme-infix-define-macro.scm (ok) + ;;#:export (infix-with-precedence2prefix ! quote-all overload overload-procedure overload-operator overload-function $nfx$ def $bracket-apply$ <- ← -> → <+ ⥆ +> ⥅ declare $ $> condx ≠ ** ⇜ ⇝ repeat % << >> & | ) ;; <> + + + ;; use only with scheme-infix-define-macro.scm enabled + ;;#:re-export (local-eval the-environment) + + #:re-export (for + for-basic + for-next + for-basic/break + for-basic/break-cont + for/break-cont + for-each-in + in-range + reversed + + define-overload-procedure + overload-procedure + + define-overload-existing-procedure + overload-existing-procedure + + define-overload-operator + overload-operator + + define-overload-existing-operator + overload-existing-operator + + define-overload-n-arity-operator + overload-n-arity-operator + + define-overload-existing-n-arity-operator + overload-existing-n-arity-operator + + overload-function ;; see how to do the same for operator, see the possible problem with infix precedence? + + + ;;$ovrld-square-brackets-lst$ + + overload-square-brackets + ;;find-getter-and-setter-for-overloaded-square-brackets + find-getter-for-overloaded-square-brackets + find-setter-for-overloaded-square-brackets + + infix-operators-lst + set-infix-operators-lst! + replace-operator! + ) + + #:replace (do when unless) + + #:export ($nfx$ + !*prec + + def $bracket-apply$ <- ← -> → <+ ⥆ +> ⥅ declare $> $+> condx ≠ ** ⇜ ⇝ repeat % << >> & $ | ) ;; <> is already defined in Guile + +) ;; end module definitions + + + +(include-from-path "def.scm") + +;; must know 'for' before use unless that scheme will suppose a procedural call instead of a macro expansion +;; and will issue definition in expression context error + +(include-from-path "set-values-plus.scm") + +(include-from-path "declare.scm") +(include-from-path "condx.scm") +(include-from-path "block.scm") +(include-from-path "not-equal.scm") +(include-from-path "exponential.scm") +(include-from-path "while-do-when-unless.scm") +(include-from-path "repeat-until.scm") +(include-from-path "modulo.scm") +(include-from-path "bitwise.scm") + +(include-from-path "scheme-infix.scm") + +;;(include-from-path "scheme-infix-define-macro.scm") + +(include-from-path "slice.scm") + +(include-from-path "assignment.scm") +(include-from-path "apply-square-brackets.scm") diff --git a/array.scm b/array.scm index fec7e79..b927eb4 100644 --- a/array.scm +++ b/array.scm @@ -1,5 +1,7 @@ ;; arrays +;; guile version + ;; This file is part of Scheme+ ;; Copyright 2021-2023 Damien MATTEI @@ -22,6 +24,28 @@ ;; TODO : make a version vector with resizable arrays using classes ;; cf: https://www.gnu.org/software/guile/manual/html_node/GOOPS.html +(define-module (array) + + #:use-module (for_next_step) + + #:export (make-array-2d + array-2d-ref + array-2d-set! + create-vector-2d + negative-vector-index + function-array-n-dim-ref + function-array-n-dim-set! + display-array-2d + dv-2d + funct-array-2d-set! + funct-array-2d-ref + array-ref-set! + srfi25-array-set!)) + + +;;(include "./for_next_step.scm") + + ;; the value v should be put before in a let to avoid multiple evaluation after macro expand (define-syntax make-array-2d (syntax-rules () @@ -54,17 +78,24 @@ ((_ array lin col val) (vector-set! (vector-ref array lin) col val)))) ;; create a vector of line and column with a function +;; (define (create-vector-2d fct lin col) +;; {v <+ (make-vector lin)} +;; ;;(display "ok") (newline) +;; (for ({l <+ 0} {l < lin} {l <- l + 1}) +;; {v[l] <- (make-vector col)} +;; (for ({c <+ 0} {c < col} {c <- c + 1}) +;; {v[l][c] <- (fct l c)})) +;; v) + +;; create a vector (or array) of line and column with a function (define (create-vector-2d fct lin col) - {v <+ (make-vector lin)} - ;;(display "ok") (newline) - (for ({l <+ 0} {l < lin} {l <- l + 1}) - {v[l] <- (make-vector col)} - (for ({c <+ 0} {c < col} {c <- c + 1}) - {v[l][c] <- (fct l c)})) + (define v (make-vector lin)) + (for ((define l 0) (< l lin) (set! l (+ l 1))) + (vector-set! v l (make-vector col)) + (for ((define c 0) (< c col) (set! c (+ c 1))) + (array-2d-set! v l c (fct l c)))) v) - - ;; scheme@(guile-user)> (define arr (make-array-2d 10 7 0)) ;; scheme@(guile-user)> (array-n-dim-ref arr 4 3) ;; 0 @@ -128,7 +159,8 @@ (syntax-rules () ((_ array) (for-basic (y 0 (- (vector-length array) 1)) - (display-nl (vector-ref array y)))))) + (display (vector-ref array y)) + (newline))))) ;; > (define _quai 34) @@ -139,7 +171,7 @@ ((_ var) (begin ;;(display (symbol->string (quote var))) (display (quote var)) - (display-nl " = ") + (display " = ")(newline) (display-array-2d var) (newline))))) diff --git a/first-and-rest.scm b/first-and-rest.scm index dd67489..2c5d584 100644 --- a/first-and-rest.scm +++ b/first-and-rest.scm @@ -1,8 +1,13 @@ ;; this for scheme implementation other than DrRacket and that do not have first and rest -(define-syntax first - (syntax-rules () - ((_ p) (car p)))) +;; (define-syntax first +;; (syntax-rules () +;; ((_ p) (car p)))) + +;; (define-syntax rest +;; (syntax-rules () +;; ((_ p) (cdr p)))) + + +(define first car) +(define rest cdr) -(define-syntax rest - (syntax-rules () - ((_ p) (cdr p)))) diff --git a/for_next_step.scm b/for_next_step.scm index e5584d2..8d95317 100644 --- a/for_next_step.scm +++ b/for_next_step.scm @@ -1,4 +1,6 @@ -;; Copyright 2022 Damien MATTEI +;; Copyright 2022-2023 Damien MATTEI + +;; guile version ;; 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 @@ -14,11 +16,22 @@ ;; along with this program. If not, see . -;;(require (rename-in racket/base [for for-rack])) ;; backup original Racket 'for' -;; (define-module (for-next-step) -;; #:export (break continue for)) +(define-module (for_next_step) + #:export (for + for-basic + for-next + for-basic/break + for-basic/break-cont + for/break-cont + for-each-in + in-range + reversed + )) + +(include-from-path "increment.scm") + ;; > (for-basic ((k 5)) (display k) (newline)) ;; 0 @@ -505,3 +518,65 @@ ;; body ...))) ;; incrmt ;; (loop)))))))))) + + + +(define-syntax for-each-in + + (syntax-rules () + + ((_ (i seq) stmt0 stmt1 ...) (for-each (lambda (i) stmt0 stmt1 ...) + seq)))) + + +;; |kawa:2|# (in-range 5) +;; (0 1 2 3 4) +;; #|kawa:3|# (in-range 1 5) +;; (1 2 3 4) +;; #|kawa:4|# (in-range 1 5 2) +;;(1 3) +(define (in-range . arg-lst) + (define n (length arg-lst)) + (when (or (= n 0) (> n 3)) + (error "in-range: bad number of arguments")) + (define start 0) + (define stop 1) + (define step 1) + (define res '()) + + (case n + ((0) (error "in-range : too few arguments")) + ((1) (set! stop (car arg-lst))) + ((2) (begin (set! start (car arg-lst)) + (set! stop (cadr arg-lst)))) + ((3) (begin (set! start (car arg-lst)) + (set! stop (cadr arg-lst)) + (when (= 0 step) + (error "in-range: step is equal to zero")) + (set! step (caddr arg-lst))))) + + (define (arret step index stop) + (if (> step 0) + (< index stop) + (> index stop))) + + (for ((define i start) (arret step i stop) (set! i (+ step i))) + (set! res (cons i res))) + + (reverse res)) + + + +;; #|kawa:3|# (in-range 1 11 3) +;; (1 4 7 10) +;; #|kawa:4|# (reversed (in-range 1 11 3)) +;; (10 7 4 1) +;; #|kawa:5|# (in-range 8 1 -2) +;; (8 6 4 2) +;; #|kawa:6|# (reversed (in-range 8 1 -2)) +;; (2 4 6 8) +;; #|kawa:7|# (in-range 8 1 -1) +;; (8 7 6 5 4 3 2) +;; #|kawa:8|# (reversed (in-range 8 1 -1)) + +(define reversed reverse) diff --git a/increment.scm b/increment.scm index 0809ff6..b43eca3 100644 --- a/increment.scm +++ b/increment.scm @@ -5,6 +5,11 @@ ((_ x) (begin (set! x (+ x 1)) x)))) +(define-syntax inc! + (syntax-rules () + ((_ x) (begin (set! x (+ x 1)) + x)))) + (define-syntax add1 (syntax-rules () ((_ x) (+ x 1)))) diff --git a/infix-operators.scm b/infix-operators.scm new file mode 100644 index 0000000..dd86ad4 --- /dev/null +++ b/infix-operators.scm @@ -0,0 +1,66 @@ +;; guile version + + +(define-module (infix-operators) + + #:export ( infix-operators-lst + set-infix-operators-lst! + replace-operator! )) ;; end module declaration + +(include-from-path "exponential.scm") +(include-from-path "modulo.scm") +(include-from-path "bitwise.scm") +(include-from-path "not-equal.scm") + +(include-from-path "first-and-rest.scm") +(include-from-path "list.scm") + + +;; can you believe they made && and || special forms??? yes :-) but with advantage of being short-circuited,but i admit it has been a headlock for an infix solution +;; note: difference between bitwise and logic operator + + +;; a list of lists of operators. lists are evaluated in order, so this also +;; determines operator precedence +;; added bitwise operator with the associated precedences and modulo too +(define infix-operators-lst + + + (list 0 + + (list expt **) + (list * / %) + (list + -) + + (list << >>) + + (list & | ) + + ; now this is interesting: because scheme is dynamically typed, we aren't + ; limited to any one type of function + + (list < > = ≠ <= >=) ;; <> not compatible with guile + + ;;(list 'dummy) ;; can keep the good order in case of non left-right assocciative operators.(odd? reverse them) + + ) + + ) + + +(define (set-infix-operators-lst! lst) + (set! infix-operators-lst lst)) + +(define (replace-operator! op-old op-new) + (display "replace-operator! :") (newline) + ;; (display op-old) (newline) + ;; (display op-new) (newline) + (display infix-operators-lst) (newline)(newline) + (define version-number (car infix-operators-lst)) + (define new-infix-operators-lst (replace infix-operators-lst op-old op-new)) + (set-infix-operators-lst! (cons (+ 1 version-number) ; increment the version number + (cdr new-infix-operators-lst))) + (display infix-operators-lst) (newline)(newline)) + + + diff --git a/list.scm b/list.scm new file mode 100644 index 0000000..aff44cf --- /dev/null +++ b/list.scm @@ -0,0 +1,203 @@ +;; insert and set +(define-syntax insert-set! + (syntax-rules () + ((_ expr var) + (set! var (insert expr var))))) + + +;; (define-syntax insert +;; (syntax-rules () +;; ((_ el lst) (cons el lst)))) + +(define insert cons) + + +(define (only-one? expr) + (null? (rest expr))) + +(define (pair-list? expr) + (and (list? expr) (only-one? (rest expr)))) + +(define (empty? lst) + (null? lst)) + +(define empty '()) + +;; insert an element in a list (at the end) if the element is not already included in the list (note: but element could be already many times in the list! and so in the result!) +;; (insertNoDups 'k '(a bc d e f a x y z d e t g)) +;; '(a bc d e f a x y z d e t g k) +;; (insertNoDups 'k '(a bc d e f a x y k z d e t g)) +;; '(a bc d e f a x y k z d e t g) +;; > (insertNoDups 'k '(a bc d e f a x y k z d e k t g)) +;; '(a bc d e f a x y k z d e k t g) + +;; (define (insertNoDups element lst) +;; (cond +;; ((empty? lst) (cons element lst)) +;; ((equal? element (first lst)) lst) +;; (else (cons (first lst) (insertNoDups element (rest lst)))))) + +;; (define (insertNoDups element lst) +;; (if (member element lst) +;; lst +;; (reverse (cons element (reverse lst))))) ;; keep order + + +;; insert an element in a list (at the begin) if the element is not already included in the list (note: but element could be already many times in the list! and so in the result!)) +;; (insertNoDups 'k '(a bc d e f a x y z d e t g)) +;; '(k a bc d e f a x y z d e t g) +;; (insertNoDups 'k '(a bc d e f a x y k z d e t g)) +;; '(a bc d e f a x y k z d e t g) +;; > (insertNoDups 'k '(a bc d e f a x y k z d e k t g)) +;; '(a bc d e f a x y k z d e k t g) + +(define (insertNoDups element lst) + (if (member element lst) + lst + (cons element lst))) + + +;; (remove-duplicates '(a bc d e f a x y z d e t g)) -> '(g t e d z y x a f bc) +(define (remove-duplicates lst) + (cond + ((empty? lst) empty) + (else (insertNoDups (first lst) (remove-duplicates (rest lst)))))) ;; insert in a list that has NO MORE duplicates ! + + +(define (singleton-list? lst) + (and (list? lst) (null? (rest lst)))) + + +;;> (create-list '() 5) -> '(() () () () ()) +;;> (create-list 'x 5) -> '(x x x x x) +(define (create-list elem lgt) + (if (= 0 lgt) + '() + (cons elem (create-list elem (- lgt 1))))) + +;; remove duplicates but keep the list sorted +;; (remove-duplicates-sorted '(A A B C D D E F G)) -> '(A B C D E F G) +;; DEPRECATED because same as uniq +;; (define (remove-duplicates-sorted sorted-lst) +;; (reverse (remove-duplicates sorted-lst))) + + +;; like 'uniq' UNIX command but on List (suppose list is already sorted or at least identical elements are clustered) +;; (uniq '(A A B C D D E F G)) +;;'(A B C D E F G) +(define (uniq L) + (cond + ((null? L) '()) + (else + (cons (car L) + (uniq (remove-firsts-elements (car L) + (cdr L))))))) + +;; remove all the c in '(c c c c c c ... L) +(define (remove-firsts-elements c L) + (cond + ((null? L) '()) + ;; ((null? (cdr L)) (if (equal? c (car L)) + ;; '() + ;; L)) + ((not (equal? c (car L))) L) + (else + (remove-firsts-elements c (cdr L))))) + + + +;; remove last element of a list +;; +;; > (remove-last '(((1 0 0 0)) ((0 1 0 1) (1 0 1 0) (1 1 0 0)) ((0 1 1 1) (1 1 0 1) (1 1 1 0)) ((1 1 1 1)))) +;; '(((1 0 0 0)) ((0 1 0 1) (1 0 1 0) (1 1 0 0)) ((0 1 1 1) (1 1 0 1) (1 1 1 0))) +;; > (remove-last '(a b c)) +;; '(a b) +(define (remove-last lst) + (reverse (rest (reverse lst)))) + +;; > (replace '(1 (1 2 3 4 (5 6 3) 3 4)) 3 7) +;; '(1 (1 2 7 4 (5 6 7) 7 4)) +;; > (replace '() 3 7) +;; '() +;; > (replace '(1 (1 2 3 4) 3 4) 3 7) +;; '(1 (1 2 7 4) 7 4) +;; (define (replace L new old) +;; (cond ;;((null? L) L) +;; ((list? L) +;; (map +;; (lambda (lst) (replace lst new old)) +;; L)) +;; (else +;; (if (equal? L old) +;; new +;; L)))) + +;; > (replace '(1 (1 2 3 4) 3 4) 3 7) +;; '(1 (1 2 7 4) 7 4) +;; > (replace '() 7 3) +;; '() +;; > (replace '(1 (1 2 3 4) 3 4) 3 7) +;; '(1 (1 2 7 4) 7 4) +;; > (replace '(1 (1 2 3 4 (5 6 3) 3 4)) 3 7) +;; '(1 (1 2 7 4 (5 6 7) 7 4)) +;; +;; (replace 4 4 5) -> 5 +;; warning : element to replace must not be () !!! +(define (replace L old new) + + (if (list? L) + (map + (lambda (lst) (replace lst old new)) + L) + (if (equal? L old) + new + L))) + + +(define (debut n L) + (if (or (null? L) (= n 0)) + '() + (cons (first L) (debut (- n 1) (rest L))))) + +(define (debut-iter n L) + (define (iter acc ncur Lcur) + (if (or (null? Lcur) (= ncur 0)) + acc + (iter (cons (first Lcur) acc) (- ncur 1) (rest Lcur)))) + (reverse (iter '() n L))) + + +;; scheme@(guile-user)> (not-list? 4) +;; $1 = #t + +(define (not-list? L) + (not (list? L))) + + + + +;; (before-element 5 '(20 10 5 14 7)) -> '(20 10) +;; (before-element 20 '(20 10 5 14 7)) -> '() +(define (before-element x L) + (letrec ((be-rec (lambda (L) + (if (equal? (first L) x) + '() + (cons (first L) (be-rec (rest L))))))) + (be-rec L))) + +;; (start-with-element 5 '(20 10 5 14 7)) -> '(5 14 7) +(define (start-with-element x L) + (letrec ((aft-rec (lambda (L) + (if (equal? (first L) x) + L + (aft-rec (rest L)))))) + (aft-rec L))) + +;; scheme@(guile-user)> (pair-list-elements '(a b c d e f)) +;; $2 = ((a b) (c d) (e f)) +(define (pair-list-elements L) + (if (null? L) + L + (cons (list (first L) + (first (rest L))) + (pair-list-elements (rest (rest L)))))) diff --git a/overload.scm b/overload.scm index 25deaeb..933711e 100644 --- a/overload.scm +++ b/overload.scm @@ -1,4 +1,8 @@ ;; overload + + +;; guile version + ;; use with Scheme+: ;; sudo cp overload.scm /usr/local/share/guile/site/3.0 @@ -7,38 +11,39 @@ ;;(use-modules (overload)) (define-module (overload) - #:use-module ((guile)) - ;; #:use-module (srfi srfi-69 ) ;; Basic hash tables - #:use-module (srfi srfi-1) ;; any,every - #:export ( define-overload-procedure - overload-procedure - - define-overload-existing-procedure - overload-existing-procedure - - define-overload-operator - overload-operator - - define-overload-existing-operator - overload-existing-operator - - define-overload-n-arity-operator - overload-n-arity-operator - - define-overload-existing-n-arity-operator - overload-existing-n-arity-operator - - overload-function ;; see how to do the same for operator, see the possible problem with infix precedence? - - - $ovrld-square-brackets-lst$ - - overload-square-brackets - ;;find-getter-and-setter-for-overloaded-square-brackets - find-getter-for-overloaded-square-brackets - find-setter-for-overloaded-square-brackets - - )) + #:use-module ((guile)) + #:use-module (infix-operators) + ;; #:use-module (srfi srfi-69 ) ;; Basic hash tables + #:use-module (srfi srfi-1) ;; any,every + #:export ( define-overload-procedure + overload-procedure + + define-overload-existing-procedure + overload-existing-procedure + + define-overload-operator + overload-operator + + define-overload-existing-operator + overload-existing-operator + + define-overload-n-arity-operator + overload-n-arity-operator + + define-overload-existing-n-arity-operator + overload-existing-n-arity-operator + + overload-function ;; see how to do the same for operator, see the possible problem with infix precedence? + + + $ovrld-square-brackets-lst$ + + overload-square-brackets + ;;find-getter-and-setter-for-overloaded-square-brackets + find-getter-for-overloaded-square-brackets + find-setter-for-overloaded-square-brackets + + )) (define $ovrld-square-brackets-lst$ '()) ;; for square brackets @@ -181,11 +186,7 @@ (syntax-rules () ((_ orig-funct funct (pred-arg1 ...)) - ;(begin - (define orig-funct (create-overloaded-existing-operator orig-funct funct (list pred-arg1 ...))) - ;(display"Updating operators...") (newline) - ;(update-operators))))) - ))) + (define orig-funct (create-overloaded-existing-operator orig-funct funct (list pred-arg1 ...)))))) (define-syntax overload-operator @@ -339,6 +340,8 @@ (display "old-funct: ") (display old-funct) (newline) (display "new-funct: ") (display new-funct) (newline) + (replace-operator! orig-funct new-funct) ;; if problem with infix precedence use insert-operator! see Kawa code + new-funct) @@ -381,6 +384,8 @@ (display "new-funct: ") (display new-funct) (newline) (newline) + (replace-operator! orig-funct new-funct) + new-funct) diff --git a/scheme-infix.scm b/scheme-infix.scm index 03ceab1..3aa93a0 100644 --- a/scheme-infix.scm +++ b/scheme-infix.scm @@ -1,6 +1,3 @@ -;;#lang reader "SRFI-105.rkt" -;;#lang r5rs - ;; infix evaluator with operator precedence ;;(provide (all-defined-out)) ;; export all bindings @@ -57,7 +54,7 @@ #f)))) (define (!prec . terms) ;; precursor of !0 - (!0 infix-operators-lst terms)) + (!0 (cdr infix-operators-lst) terms)) ;; cdr skip version number @@ -267,44 +264,4 @@ (define (!*prec terms) ;; precursor of !* (if (null? terms) terms - (!* terms infix-operators-lst #f))) - - - - - -;; can you believe they made && and || special forms??? yes :-) but with advantage of being short-circuited,but i admit it has been a headlock for an infix solution -;; note: difference between bitwise and logic operator - - -;; a list of lists of operators. lists are evaluated in order, so this also -;; determines operator precedence -;; added bitwise operator with the associated precedences and modulo too - - -;; a list of lists of operators. lists are evaluated in order, so this also -;; determines operator precedence -;; added bitwise operator with the associated precedences and modulo too -(define infix-operators-lst - - (list - - (list expt **) - (list * / %) - (list + -) - - (list << >>) - - (list & | ) - - ; now this is interesting: because scheme is dynamically typed, we aren't - ; limited to any one type of function - - (list < > = ≠ <= >=) ;; <> is already defined in Guile - - - ;;(list 'dummy) ;; can keep the good order in case of non left-right assocciative operators.(odd? reverse them) - - ) - - ) + (!* terms (cdr infix-operators-lst) #f))) ;; cdr skip version number