I can't seem to get multi-line expressions to work on the command line of
the newlisp interpreter. I'm getting a "missing parenthesis" error when I
attempt it.
What am I missing here?
Also, is it possible to evaluate or "run" a file of newlisp code from the command line.
Using RH 9.0. newLISP v.8.2.0
Pointers to docs and other threads welcome.
thanks
tim
missing parenthesis/evaluating file from command line
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
Hi Tim,
newLisp's command-line environment is exacty that -- a line-oriented environment. When a ENTER is pressed or a newline sequence encountered, newLisp scurries off to evaluate the line. If the line is not completely self-contained, the evaluator complains. newLisp's command-line environment is not a good environment for entering muli-line expressions.
Using the (load "filename.lsp"), you can write code using your favorite editor and then 'load' the file into newLisp. The act of loading files executes the commands in that file so that file content such asandwill be executed and, as a result, be defined.
newLisp's command-line environment is exacty that -- a line-oriented environment. When a ENTER is pressed or a newline sequence encountered, newLisp scurries off to evaluate the line. If the line is not completely self-contained, the evaluator complains. newLisp's command-line environment is not a good environment for entering muli-line expressions.
Using the (load "filename.lsp"), you can write code using your favorite editor and then 'load' the file into newLisp. The act of loading files executes the commands in that file so that file content such as
Code: Select all
(set 'mystring "this is my string")
Code: Select all
(define (magoo arg1)
(if (!= arg1 0)
(magoo (- arg1 1)) ))
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
When you use the newlisp-tk frontend you can enter multi-line exprsssions in one of the code browser editors and the hit the red eval button. There are two one for eval one for eval-print.
When in a shell window without the frontend, you can enter:
[cmd]
(define (foo x)
(+ x x))
[/cmd]
It will store the lines after the first [cmd] tag and not evaluate until another line with the closing [/cmd] tag is found. But editing is limited. I think this is also documented in the manual.
When on Linux/UNIX you can use the 'edit' macro in init.lsp which will pop up an editor, when you save it gets autonmatically loaded again and evaluated, the poor man's IDE :). You may have to customize the edit-macro for the name/location of your editor. This should also work on Win32 is customized correctly.
Lutz
When in a shell window without the frontend, you can enter:
[cmd]
(define (foo x)
(+ x x))
[/cmd]
It will store the lines after the first [cmd] tag and not evaluate until another line with the closing [/cmd] tag is found. But editing is limited. I think this is also documented in the manual.
When on Linux/UNIX you can use the 'edit' macro in init.lsp which will pop up an editor, when you save it gets autonmatically loaded again and evaluated, the poor man's IDE :). You may have to customize the edit-macro for the name/location of your editor. This should also work on Win32 is customized correctly.
Lutz
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
<Lutz>
When on Linux/UNIX you can use the 'edit' macro in init.lsp which will pop up an editor, when
you save it gets autonmatically loaded again and evaluated, the poor man's IDE :). You may have
to customize the edit-macro for the name/location of your editor.
</Lutz>
<Tim>
Thank you Lutz. That's very helpful. I've been looking thru docs that I have
and have not yet found references to 'edit-macro. Can you point me to more
info on edit-macro and init.lsp
thanks
</tim>
When on Linux/UNIX you can use the 'edit' macro in init.lsp which will pop up an editor, when
you save it gets autonmatically loaded again and evaluated, the poor man's IDE :). You may have
to customize the edit-macro for the name/location of your editor.
</Lutz>
<Tim>
Thank you Lutz. That's very helpful. I've been looking thru docs that I have
and have not yet found references to 'edit-macro. Can you point me to more
info on edit-macro and init.lsp
thanks
</tim>
the edit macro is not documented anywhere, neither are the [cmd] ... [/cmd] tags, which are used by frontends (i.e. newlisp-tk) to communicate with newLISP.
On Linux/UNIX newLISP looks for init.lsp in /usr/share/newlisp, on Win32 it looks for init.lsp in the startup directory of newlisp.exe. You find init.lsp in both, the source and the binary Win32 distribution. Its contains the follwoing macro:
and you use it like this:
(edit foo)
where foo is any symbol, no quote required and the symbol does not need to exist. Vi, or any other editor will pop up and you can edit. When you save, the function will be saved and automatically loaded.
I also would like to point you to newlisp-ide-xxx.tgz it's a web based simple IDE for newLISP. You can run it using newLISP's httpd server (in the examples/directory of the source distruibution and in the manual) or run it at your ISP (watch security!) or most other webservers. It is especially useful when developing stuff for the web. It also can execute shell commands, and other nifty stuff. I use it on an ISP/private site, where I do have no shell access and even there I compile newLISP and other stuff using this IDE (don't tell anybody ;) ).
Lutz
On Linux/UNIX newLISP looks for init.lsp in /usr/share/newlisp, on Win32 it looks for init.lsp in the startup directory of newlisp.exe. You find init.lsp in both, the source and the binary Win32 distribution. Its contains the follwoing macro:
Code: Select all
(if (< (& 0xF (last (sys-info))) 5)
(begin
(define-macro (edit _func)
(save (string _func) _func)
(! (string "/usr/bin/vi " _func))
(load (string _func)))
(global 'edit)))
(edit foo)
where foo is any symbol, no quote required and the symbol does not need to exist. Vi, or any other editor will pop up and you can edit. When you save, the function will be saved and automatically loaded.
I also would like to point you to newlisp-ide-xxx.tgz it's a web based simple IDE for newLISP. You can run it using newLISP's httpd server (in the examples/directory of the source distruibution and in the manual) or run it at your ISP (watch security!) or most other webservers. It is especially useful when developing stuff for the web. It also can execute shell commands, and other nifty stuff. I use it on an ISP/private site, where I do have no shell access and even there I compile newLISP and other stuff using this IDE (don't tell anybody ;) ).
Lutz