Load Confusion

Started by Tim Johnson, October 24, 2004, 06:46:57 PM

Previous topic - Next topic

Tim Johnson

According to newlisp docs 'load :

Loads and translates newLISP from a source file specified ....

... evaluates the expressions contained in the file ...

... when loading is successful load returns true



The following console session uses cgi.lsp copied as cgitest.lsp

I note that the console is unresponsive until <enter> is pressed

a second time (why is that?).

Furthermore after a second <enter> and seeing 'true, a function

contained in the file is not recognized:

Console copy follows

> (load "cgitest.lsp")



true

> (url-translate "abcdef")



invalid function : (url-translate "abcdef")



;; Does not seem that cgitest.lsp is being evaluated

;; What am I doing wrong?

thanks

tim
Programmer since 1987. Unix environment.

Tim Johnson

#1
I've answered part of my question. Forgot to use the context protocol.

Should have been:

(CGI:url-translate "abc%20def")    ;; or something like that.

;; DUH!!



The questions till remains :

Why the extra carriage return (<enter>) to evaluate the

'load form?

thanks

tim

P.S. I promise not to figure out that last one as quickly :-)
Programmer since 1987. Unix environment.

Lutz

#2
cgi.lsp is a file containing subroutines to process webpages. Typically it is the first file loaded in .cgi file on a website. CGI works via standardd I/O so what the file is doing is trying to read the HTTP header and potential HTTP form variables.



Header and body in an HTTP transmission are seperated by 2 linefeeds. So when you load this file into the the console, it awaits standard inout passed to it from the webserver.



It is not a programs to be executed directly in the console.



Study programs like newlisp-ide-xxx.tgz or newlisp-wiki-xxx.tgz to see how this works.



Lutz

Tim Johnson

#3
Aha!

FYI: I am an "old" (in more ways than one) web programmer, but

have always loaded modules "passively".  (evaluate, but execute

from calling code)

I see a 'readline in the code now.



Thanks again

tim
Programmer since 1987. Unix environment.

Lutz

#4
' loading then calling', yes that is what I do too normally and is how the other modules shipped with newLISP work. Just cgi.lsp makes a difference and executes stuff while loading ;)



It has then all variables parsed for you, no matter if they came in a GET or POST request.



Lutz

Tim Johnson

#5
FYI2: Lately I've been using C, python and rebol. Rebol is hugely productive, but

I wouldn't be here if it were the end-all & be-all :-). Some drawbacks there.........



One interesting feature of rebol is that you can 'load a module (which returns a 'block' of

code). The programmer can dynamically append to that block during runtime, and then

'do (evaluate) it. That has the effect of modifying or appending to the original context

without changing the original module source. I think mzscheme has something like that.

 

Just curious, was there a specific reason for the development of newlisp? My niece

worked for Rebol Technologies in 2000. She has many interesting stories to tell!



Regards

tim
Programmer since 1987. Unix environment.

HPW

#6
Quote
One interesting feature of rebol is that you can 'load a module (which returns a 'block' of code). The programmer can dynamically append to that block during runtime, and then 'do (evaluate) it.


Since there is no difference in LISP between code and data, there no reason you can not do this in newLISP.

Read a block of source-code as a string and append to it and then eval the whole string.

Dynamic code generation is fun with LISP. A technic which I use a lot even in plain old autolisp.



'EVAL' and 'SOURCE' are the right commands for the job.
Hans-Peter

Lutz

#7
You don' have to go via strings, imagine the following:



(set 'block '(begin (print "hello ")))



(eval block) => hello



(push '(println "world") block -1) ; push new statement at the end of block



(eval block) => hello world



and of course you can do the same thing with whole functions



(define (myprog) (printl "hello "))



(myprog)=> hello



(push '(println "world") myprog -1)



(myprog) => hello world



And there is also the possibility in newLISP to merge whole modules/contexts using 'new' .



Lutz

Tim Johnson

#8
Great thread folks! Keep it up. I'm just sitting here taking notes and enjoying it.

.....autolisp! that brings back some memories .....
Programmer since 1987. Unix environment.