newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Tim Johnson on October 24, 2004, 06:46:57 PM

Title: Load Confusion
Post by: Tim Johnson on October 24, 2004, 06:46:57 PM
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
Title:
Post by: Tim Johnson on October 24, 2004, 08:10:46 PM
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 :-)
Title:
Post by: Lutz on October 25, 2004, 05:10:43 AM
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
Title:
Post by: Tim Johnson on October 25, 2004, 08:26:48 AM
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
Title:
Post by: Lutz on October 25, 2004, 08:42:43 AM
' 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
Title:
Post by: Tim Johnson on October 25, 2004, 09:33:04 AM
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
Title:
Post by: HPW on October 25, 2004, 10:37:22 AM
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.
Title:
Post by: Lutz on October 25, 2004, 11:12:53 AM
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
Title:
Post by: Tim Johnson on October 25, 2004, 11:29:39 AM
Great thread folks! Keep it up. I'm just sitting here taking notes and enjoying it.

.....autolisp! that brings back some memories .....