Page 1 of 1

What are mdl and estack?

Posted: Tue May 26, 2009 10:31 am
by Kazimir Majorinc
These symbols are in (symbols) but I do not know their purpose.

Posted: Tue May 26, 2009 11:36 am
by Lutz
For convenience newLISP contains a predefined 'module' function to load modules from the standard location:

Code: Select all

(set (global 'module) (fn (mdl) 
    (load (append (env "NEWLISPDIR") "/modules/" mdl))))

; example

(module "mysql.lsp")
'estack' is an undocumented experimental function returning the contents of the environment stack, which stores the binding of variables before entering a user defined function. Bindings are stored in an association list:

Code: Select all

(define (foo x y z) 
    (println "-> " (estack)) (bar x))

(define (bar x) 
    (println "->" (estack)) x)

(set 'x 1 'y 2  'z 3)

> (foo 11 22 33 44 55)
-> (($args ()) (z 3) (y 2) (x 1))
->(($args (44 55)) (x 11) ($args ()) (z 3) (y 2) (x 1))
11
> 
You could query the prior stat of a variable doing: (lookup 'var (estack)). The function may disappear at some point and there are no plans to make the environment stack writable by the user, as some programming languages allow. This would only encourage to write unreadable hard to understand code.

Posted: Wed May 27, 2009 11:09 am
by Kazimir Majorinc

Code: Select all

> (foo 11 22 33 44 55)
-> (($args ()) (z 3) (y 2) (x 1))
->(($args (44 55)) (x 11) ($args ()) (z 3) (y 2) (x 1))
11
> 
Looks good!
... This would only encourage to write unreadable hard to understand code.
But it could be fun!

Posted: Wed May 27, 2009 1:10 pm
by newdep
hehehe yeah we could rewrite the 99-bottle-of-beer in args ;-)
Would look even worse then this one ;-)

Code: Select all

(set  'y 99 'z '( " bottles" " of beer on the wall" "no more" "Take one down and pass it around, "
"Go to the store and buy some more, " ".\n" ))
(set 'a (z 0) 'b (z 1) 'c (z 2) 'd (z 3) 'e (z 4) 'f (z 5) 'g (0 -1 a) 'h (0 8 b) 'i (-2 d))
(for (x y 0)
  (println
   (if (> x 0) x (title-case c)) (if (= x 1) g a) b i (if (= x 0) c x) (if (= x 1) g a) h f
     (if (= x 0) e d) (case x (0 y) (1 c) (true (- x 1)))  (if (= x 2) g a) b f ))