The 9.4.0 newLISP manual

Started by Lutz, June 09, 2008, 06:05:01 AM

Previous topic - Next topic

newdep

#45
9.9.95 typo...



syntax: (copy exp)



Make a copy from evaluating expression in exp. Some built-in functions are destructive, changing the original contents of a list, array or string they are working on. With copy their behvior can be made non-destructive.





should be "behavior"
-- (define? (Cornflakes))

DrDave

#46
I was looking at some functions in the manual and noted EXEC enables launching a process, such as another newlisp process (among others), and passing a command to it.  For example,
(exec "newlisp" "(+ 3 4)" )  -->
7
true

For those that use newLISP quite a lot, I'm sure that the text in the manual is sufficient. But for new folks, or those that aren't hard-core users (I'm in that group), a couple of examples of code that really works would be very helpful.



I suspect that this could be useful if a blocking function needs to be called. So rather than calling the blocking function in the first newlisp process, launch a second newlisp process and call the blocking function and somehow capture the result. It is not clear to me how to capture the result from the second process. To where does the result go? How to determine if the result is availalble (maybe run a timer and check for wherever the result goes being true? Or somehow check for the final return value of true?)
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2

Lutz

#47
Note that when using the second syntax of 'exec' feeding stdin to the process. Only 'true' or 'nil' is returned. The '7' you are seeing is only stdout of the process showing up in the your console terminal. Only when not feeding stdin, the output of the process is collected and comes back in a list:


> (exec "newlisp -e '(+ 3 4)'" )
("7")
>


For what you are suggesting 'process' with the pipes option may be the better solution, because you can set up a non-blocking bidirectional communication and use 'peek' to check if something is ready on the input pipe:


> (map set '(myin nlout) (pipe))
(3 4)
> (map set '(nlin myout) (pipe))
(5 6)
> (process "/usr/bin/newlisp" nlin nlout)
15763
> (write-buffer myout "(+ 3 4)n")
8
> (peek myin)
2
> (read-line myin)
"7"
> (write-buffer myout "(exit)")
6
> (peek myin)
0
>


Look also into 'net-eval' which allows you to distribute processes on different machines on a network. Its blocking but can also be event driven when a node has a result ready.



If you are on Mac OS X, Linux or other Unix you should also look into newLISP's Cilk API with the functions 'spawn', 'sync' etc.

DrDave

#48
Thanks for the explanation.



This code doesn't work for me (Windows XP pro, newLISP 9.3.0)
> (exec "newlisp -e '(+ 3 4)'" )
("7")
>


Here is the result I get
("" "missing parenthesis : "...'(+                         \168225\""")
(There are probably more spaces betwee the +  and \, but I didn't count them all.)
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2

Lutz

#49
Try this:


> (exec {newlisp -e "(+ 3 4)"})
("7")
>


Quotes are not permitted on Windows as token delimiters on the command line, using curly braces as the outer string delimiters you can use double quotes inside.



ps: redundant parentheses removed

DrDave

#50
Thanks.



This works as you wrote it
> (exec {(newlisp -e "(+ 3 4)")})
("7")
>


This also works with one set of parentheses eliminated
> (exec {newlisp -e "(+ 3 4)"})
("7")
>

Also this variation
> (exec "newlisp -e "(+ 3 4)"")
("7")
>
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2

newdep

#51
regarding 'inc and 'dec.. I think the manual needs an addon..



when using 'inc excluding place and num

'inc will increase by itself.  like in (inc)



Any increment of a value afterwards using place will

start from that value on..Except when place was initialized first.



i.e.



If X is a list then (X (inc)) will run until 'ERR:..out bound of bound" occeurs

the following (inc Z) will continue where (inc) left off..









PS:

if (inc) is a feature? then ->

* how do i reset (inc) ?

* could (inc) always start at 0 <-initialy at newlisp startup ? and (inc place) at 1 ?
-- (define? (Cornflakes))

DrDave

#52
Quote from: "newdep"... I think the manual needs an addon..



when using 'inc excluding place and num

'inc will increase by itself.  like in (inc)




Are you saying that you want (inc) to be pointing to a variable such as  'inc-value that will be incremented by 1 (integer only) with every call of (inc)  ? In other words, it would be doing this behind the scenes:


(inc 'inc-value)

And the user can both query and change 'inc-value at will?



If so, I don't see the point of it.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2

newdep

#53
when starting newlisp and running (inc) it will show 1



if (inc) is a feature you could use (inc) as an implicit index counter

but because at the first (inc) it starts at a 1 its of no use ;-)

(this is my request for (inc) starting at 0 initialy at newlisp startup)



Im just wondering if (inc) is a feature, which is usefull, but how to

reset it then back to 0 ?



(inc) will only increase



(inc a) will take value of (inc)



(setq b 0)



(inc b) is always 1



(X (inc)) can't be used as an index because (inc) is always +





the use of (inc) is not documented so im just wondering about its use..
-- (define? (Cornflakes))

Lutz

#54
(inc) -> should throw an error. Its a bug!

DrDave

#55
Quote from: "Lutz"(inc) -> should throw an error. Its a bug!


throws error in v 9.3.0 on Win32
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2

m35

#56
In http://www.newlisp.org/downloads/newlisp_manual.html#bind">bind for Manual v.9.4.5 rev-12



The line

"The return value of bind is the value of the last association."

is written twice.

newdep

#57
manual 10.0



missing parenthesis in -> when <-



(when (read-line)

   (set 'result (analyze (current-line)))

   (report result

   (finish)

)
-- (define? (Cornflakes))

cormullion

#58
syntax statements for cond and chop are missing final parentheses



(Don't ask why/how I spotted that - it's something I'm working on at the moment...!)



Also, "co" in contents jumps to copy - should jump to command-event...

xytroxon

#59
Errata:



Code Patterms:



23. Extending newLISP

,,,

#include <stdio>

#include <stdlib>

#include <ctype>> <<<--- double ">"



-------------



newLISP manual:



dec !

syntax: (dec place [num])

...

example:

...

Places in a list structurei <<<--- extra "i" at the end of structure.



---------
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976