Swarm in newLISP

For the Compleat Fan
Locked
Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Swarm in newLISP

Post by Fanda »

I am playing with the simulation of swarm.

You can find it here as a file swarm.lsp:
http://www.volny.cz/fsodomka/newlisp/

Enjoy, Fanda

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

Post by newdep »

Thats a dammmmm nice one !
-- (define? (Cornflakes))

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

Post by Lutz »

Fantastic, beautiful!

Lutz

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

Feel free to change parameters to see what it does. It's really addicting :-)

Fanda

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Very cool!

Peter

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

Post by Lutz »

Here is a simple program to run Fanda's swarm.lsp and inversi.lsp without newlisp-tk just using the concole app newlisp and a Tcl/Tk installation: http://newlisp.org/index.cgi?page=Tk_and_newLISP

Lutz

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

Unfortunately, 'peek' is only available on UNIX like operating systems =>

Code: Select all

(while (= (peek myin) 0))
will not work on Windows.

Just wanted to let you know...

Fanda

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

Post by Lutz »

Oops, I forgot, thanks for letting me know, on Win32 you still got to do: newlisp-tk swarm.lsp .

Lutz

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Just checked. Cool thing!
WBR, Dmi

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

Hello!
I have been trying to make it work on Windows.

Some scripts run just fine, when I comment the line:
(while (= (peek myin) 0))

I added error checking and divided (write-line ...) into 2 lines. Inversi doesn't want to run, if I write (write-line ...) on 1 line only. (I don't know why.)

Code: Select all

; tk function to pass commands to Tcl/Tk
(define (tk)
  (write-line (append "if { [catch { puts [" (apply string (args)) "] }] } { " [text] tk_messageBox -message "$errorInfo"; exit }
    [/text]) myout)
  (read-line myin))
(global 'tk)
I also tried some tests for tk function:

Code: Select all

; call inside the call
(tk "tk_messageBox -type ok -message {You clicked '" (tk "tk_messageBox -type yesno -message {Click on something :-)}") "'!}")

; catches error correctly:
;(tk "set x [expr {1 +}]")

; it doesn't catch bad brackets -> freezes up afterwards!
;(tk "set x {whatever here")
With this tk function both Inversi and Swarm run fine on Windows.

Fanda

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

Post by Lutz »

You may check if the the 'read-line' on a pipe in Windows blocks or not when no data is available. On Unix 'read-line' will not block but return a 'nil'. This is why the (peek myin) comes in handy.

If 'read-line' doesn't block on Windows either, you might just put (sleep ..) statements before reading to make sure data is available. Perhaps splitting the 'write-line' changes the timing.

Or, if it blocks, make sure there is always data to read ready from the TclTk side. If no data is available and it blocks, newLISP would sit in the 'read-line' and freeze.

I will try your new (tk ..) function with error checking when I get to a Windows machine and incorporate it into nl-tcltk.


Lutz

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

- I believe that 'read-line' on Windows blocks when no data is available. I think, we can prove it using "call inside the call" - without 'peek' on Unix it should return "You clicked 'nil'". (Could anybody try it on Unix without 'peek', please?)
On Windows it waits and says correctly 'yes' or 'no'.

- We could write 2 versions of tk function:
if OS is Unix -> tk with 'peek' - else - tk without it

- My guess when splitting the 'write-line' to 2 lines was that Tcl needs some spaces or end of line characters to correctly process the command(s).

- The 3rd tk test of catching the bad brackets freezes up because Tcl can't process the command correctly - it's missing the brackets, but will not throw an error because there is no clear beginning and the end of commands (including catch and puts).

- I would like to add a constant to nl-tcltk

Code: Select all

; constant to differentiate between newlisp-tk and this wrapper
(constant (global 'NL-TCLTK) true)
It's useful when exiting the script
nelisp-tk -> deiconify '.'
wrapper -> exit wish and exit newlisp

Fanda

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

Post by Lutz »

On UNIX/OSX:

get first dialog box "click on something",
click 'yes' which brings a second dialog box "you clicked on 'yes'",
click 'ok' which returns "ok" in newLISP.

Lutz

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

Post by Lutz »

But I am not sure if it will always work? becuase I have put in the (peek ..) because I had instances where it would go into read-line to fast and return 'nil' before a string had arrived.

Lutz

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

Cool, it means that this can be used as a test if 'read-line' blocks or not.

Fanda

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

Post by Lutz »

.. and it also runs fine Demo.lsp, Hanoi.lsp, Turtle.lsp and Random.lsp. Have not figured out yet why it doesn't run Mouse.lsp after color change, but now with your new 'tk' I get at least ans error message box and it wouldn't run on the old 'tk' either.

Lutz

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

There is a new version 0.07:
- it doesn't show an error when closing the window (=> it's a little bit slower than 0.06)
- window has a different size in x and y (MX MY) and can be resized!
- Tk code clean up
- can be run by both newlisp-tk and Tk wrapper (exits correctly)

Visually it's pretty much the same...

Fanda

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

Post by newdep »

-- (define? (Cornflakes))

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

Mandelbrot Set + Swarm = MandelSwarm:
http://www.ventrella.com/Tweaks/MandelT ... Swarm.html

Fanda

Locked