What are mdl and estack?

Started by Kazimir Majorinc, May 26, 2009, 03:31:40 AM

Previous topic - Next topic

Kazimir Majorinc

These symbols are in (symbols) but I do not know their purpose.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Lutz

#1
For convenience newLISP contains a predefined 'module' function to load modules from the standard location:


(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:


(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.

Kazimir Majorinc

#2

> (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!


Quote... This would only encourage to write unreadable hard to understand code.


But it could be http://mifise.com/we-hate-hotlinker/kurioses-fortbewegungsmittel.flv">fun!
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

newdep

#3
hehehe yeah we could rewrite the 99-bottle-of-beer in args ;-)

Would look even worse then this one ;-)
(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 ))
-- (define? (Cornflakes))