abaddon1234 wrote:that let and letex are the exception of a general left to right evaluation for setting symbols? Or is it more complicated?
เล่นจีคลับผ่านเว็บ
let and
letex are using the outer binding of given symbols for initialization; e.g.:
Code: Select all
sr@free:~$ newlisp
newLISP v.10.6.4 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h
> (letex (x 1 y 2 z 3) '(x y z))
(1 2 3)
> ; but:
> (letex (x 1 y (+ x 1) z (+ y 1)) '(x y z))
ERR: value expected in function + : nil
> ; but:
> (set 'x 10 'y 11)
11
> (letex (x 1 y (+ x 1) z (+ y 1)) '(x y z))
(1 11 12)
>
My point regarding
set - denoted as a
special form in other Lisps - has been, that it should stated somewhere in the manual, that it follows the general rule of left-to-right evaluation using formerly
set bindings at the same level (there is no new level of bindings):
Code: Select all
sr@free:~$ newlisp
newLISP v.10.6.4 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h
> (set 'x 1 'y (+ x 1) 'z (+ y 1)) (list x y z)
3
(1 2 3)
>
That there are no new bindings introduced is clear, but
set - as well as
let - guaranteed to follow the general left-to-right evaluation rule has not been self-evident to me. Think of parallelization opportunities, if this would not been the case; on the other side parallelization could be dangerous in case of side-effects.
Possibly some thoughts along 'pure functional programming is good for parallelization, because it has no side effects' has made my thinking more complicated than needed here.
It is probably correct to say for newLISP, that the general rule of left-to-right evaluation:
- also applies for expressions like set, let - even if denoted as special forms in other Lisps -;
- does not apply only, if explicitely stated so.
Taking the definition of
special forms from the newLISP manual (different from other Lisps):
manual wrote:
Lisp functions that do not evaluate all or some of their arguments are called special forms.
; denoting something as
special form there only implies, that the general rule of left-to-right evaluation does not apply to
all arguments.
To make a long story short:
Lutz wrote:
Evaluation order in general is always depth first from left to right.
Where
- arguments are evaluated - like for function calls and also for expressions like let -, and
- nothing is said about a special evaluation order,
left-to-right evaluation applies.
Note: It is possible, of course, to write some macro for changing evaluation order by rearranging
to be evaluated macro arguments.