so i drop off the idea of a single assignment operator, there will be 2 ,<- for single assignment when the variable has been previously defined (at upper level), and another <+ that add a variable in the environment using define.
Other possibility is to have a single assignment operator <- and to declare the variables not previously defined at upper level.
All this was already done in Scheme+ :
here is what looks like
the module definition :
(define-module (Scheme+Guile)
#:export (def $bracket-apply$ <- -> <+ declare $ condx <> )
)
(include "def.scm")
(include "Scheme+Guile/array-square-brackets.scm")
(include "Scheme+Guile/assignment.scm")
(include "declare.scm")
(include "condx.scm")
(include "block.scm")
(include "not-equal.scm")
and so, the code for the 2 assignment operator :
Preview:
(define (subset-sum-guile L t)
{ls <+ (length L)}
{dyn <+ dyna[ls t]}
{cpt <- {cpt + 1}} ;; cpt has been already defined at toplevel
;; dyna[ls][t] means 0: unknown solution, 1: solution found, 2: no solution
(condx [{dyn <> 0} (one? dyn)]
[(null? L) {dyna[ls t] <- 2} #f] ;; return #f
[exec {c <+ (first L)}]
;; c is the solution
[{c = t} {dyna[ls t] <- 1} #t] ;; return #t
[exec {R <+ (rest L)}]
;; continue searching a solution in the rest
[{c > t} {s <+ (subset-sum-guile R t)}
{dyna[ls t] <- (one-two s)}
s] ;; return boolean value
;; else : c < t at this point
;; c is part of a solution OR not part of a solution
[else {s <+ {(subset-sum-guile R {t - c}) or (subset-sum-guile R t)}}
{dyna[ls t] <- (one-two s)}
s])) ;; return boolean value
and the code which use a single operator and a declare (it is a define unspecified):
Preview:
(define (subset-sum-guile-dec L t)
(declare ls dyn c R s)
{ls <- (length L)}
{dyn <- dyna[ls t]}
{cpt <- {cpt + 1}} ;; cpt has been already defined at toplevel
;; dyna[ls][t] means 0: unknown solution, 1: solution found, 2: no solution
(condx [{dyn <> 0} (one? dyn)]
[(null? L) {dyna[ls t] <- 2} #f] ;; return #f
[exec {c <- (first L)}]
;; c is the solution
[{c = t} {dyna[ls t] <- 1} #t] ;; return #t
[exec {R <- (rest L)}]
;; continue searching a solution in the rest
[{c > t} {s <- (subset-sum-guile-dec R t)}
{dyna[ls t] <- (one-two s)}
s] ;; return boolean value
;; else : c < t at this point
;; c is part of a solution OR not part of a solution
[else {s <- {(subset-sum-guile-dec R {t - c}) or (subset-sum-guile-dec R t)}}
{dyna[ls t] <- (one-two s)}
s])) ;; return boolean value
the two syntax can be mixed but i do not think it is a good idea to have 2 coding style in the same project, also the position of 'declare' or '<+' is depending of the possibility of the used Scheme implementation to have define placed everywhere more or less, in the worse case the 'declare' or '<+' have to placed at top of the body of the procedure.
The way python declare them, note that i have no regret to not be able to define variables nested in a branch of code the way python do it that can be seen from the whole procedure.I do not think it is a good idea and useful. But i hoped to be able to avoid a 'declare' at the top or somewhere but declaration even in Scheme could be necessary with some typed Scheme or when using object oriented features of some Scheme perheaps that used typed variables (for overloading function? not sure it exist in Scheme also ,even in OOP).So this is not a great problem.
Damien