What are mdl and estack?

Notices and updates
Locked
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

What are mdl and estack?

Post by Kazimir Majorinc »

These symbols are in (symbols) but I do not know their purpose.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

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

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post 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 ))
-- (define? (Cornflakes))

Locked