newLISP Fan Club

Forum => newLISP in the real world => Topic started by: gcanyon on October 24, 2006, 07:00:35 AM

Title: Can't get runtk to work?
Post by: gcanyon on October 24, 2006, 07:00:35 AM
I'm trying to use runtk to call tk, and getting an error. Here's the error:



invalid function : (map set  '(myin tcout)   (pipe))



Thanks for any help -- Geoff



This is the code I tried to run. It's a combination of the runtk file with the swarm example code.


#!/usr/bin/newlisp

; setup communications to Tcl/Tk
(map set '(myin tcout) (pipe))
(map set '(tcin myout) (pipe))
(process "wish" tcin tcout)

; 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)

  (let (str "")
    (while (starts-with (setq str (read-line myin)) "newLISP:")
      (eval-string ((length "newLISP: ") -1 str)))
    str))
(global 'tk)

;; this is for compatibility with newlisp-tk for running
;; the Demo.lsp programs distributed with newlisp-tk
;; for new programs just use 'puts' without the 'Newlisp' wrapper
(tk "proc Newlisp { command } { puts $command }")

;; exit when main window is closed
(tk "bind . <Destroy> {puts {(exit)}}")

;;
;; Swarm simulation
;;
;; Simulation of the swarm of flies. Written as a test of concepts of complex systems.
Title:
Post by: Lutz on October 24, 2006, 11:24:20 PM
Have you tried to run the programs without combining, as described here?

http://newlisp.org/index.cgi?Tips_and_Tricks



Lutz
Title:
Post by: gcanyon on October 25, 2006, 08:19:46 AM
Quote from: "Lutz"Have you tried to run the programs without combining, as described here?

http://newlisp.org/index.cgi?Tips_and_Tricks



Lutz


Yes, with no luck. I have no idea:



-- What file name to save the runtk code as.

-- Where to save that file.

-- What to do then.



I tried:



-- Saving it as runtk (with no file extension)

-- Saving it in /usr/bin (beside newlisp)

-- putting the following code into TextWrangler and running it:


#!/usr/bin/newlisp

./runtk ~/Desktop/newLISP/newswarm.lsp


I also tried just runtk and /usr/bin/runtk



Thanks for your help,



Geoff
Title:
Post by: Lutz on October 25, 2006, 08:55:39 AM
The following assumes OS X 10.4 as minimum (comes by default with Tcl/Tk), if I remember well you are a Mac user.



(1) save the file into your home directory (probably /Users/YourName) as runtk



(2) save the swarm.lsp file also in your home directory



(3) open a terminal windows /Applications/Utilities/Termina



(4) Check if runtk and swarms.lsp are there doing a :


ls

command at the prompt.



(5) make the file runtk executable


chmod 755 runtk

(6) run the program:


./runtk swarm.lsp

(6a) as an alternative (then you can omit step (5) ) try:


newlisp runtk swarm.lsp

Some comments:

Any advanced use of newLISP (or any other scripting language) demands learning the basic UNIX commands in the Terminal application. Excutiing a file out of a text editor is practical during progragram development, but not much else (advanced Emacs and Vi users would object ;) )



Try also runinng newLISP from the Terminal application, by just doing:
newlisp
Its fun to explore newLISP doing this in an interactive manner. Multi-line defintions can be entered bracing them in [cmd],[/cmd] tags, each tag on its own line. This way it is easy to copy/paste code from the manual or website.



The file names for saving do not matter as long as you use then those names subsequently.



Lutz
Title:
Post by: gcanyon on October 25, 2006, 09:27:33 AM
Quote from: "Lutz"


Some comments:

Any advanced use of newLISP (or any other scripting language) demands learning the basic UNIX commands in the Terminal application. Excutiing a file out of a text editor is practical during progragram development, but not much else (advanced Emacs and Vi users would object ;) )



Try also runinng newLISP from the Terminal application, by just doing:
newlisp
Its fun to explore newLISP doing this in an interactive manner. Multi-line defintions can be entered bracing them in [cmd],[/cmd] tags, each tag on its own line. This way it is easy to copy/paste code from the manual or website.



The file names for saving do not matter as long as you use then those names subsequently.



Lutz


I followed the steps you gave and got the same error I got when I incorporated the  swarm code into the runtk file:



invalid function : (map?set? '(myin?tcout) ? (pipe))





Responding to your comments -- I know the basics of using the terminal application -- I could have told you how to make a file executable, for example. But my knowledge stops there -- I never would have guessed that runtk needed to be executable any more than swarmp.lsp does.



Forgive me for being a bit defensive, but I don't understand why following the directions given in the runtk file for embedding code in the file makes me somehow less "cool" than running through terminal. Since I got the same error both ways, I think my way wasn't inferior.



Further, since what I'm interested in is "program development" (as you said above) working in a text editor should be fine for me. I don't intend to use newLISP as a command in terminal -- as you might guess, I don't use terminal on a regular basis. ;-)
Title:
Post by: Fanda on October 25, 2006, 10:59:53 AM
Hello Geoff!

I just wonder - does your 'pipe' function work correctly?



I tried something like:

> (pipe)

(3 4)

> (pipe)

(5 6)

> (pipe)

(7 8)

> (pipe)

(9 10)

> (pipe)

(11 12)



I copied runtk from your first post and added the swarm.lsp - creating the new file newswarm.lsp.

After executing: newlisp newswarm.lsp

it works just fine on Windows XP.





Lutz, what does error:

invalid function - code 23

really stand for?



Fanda
Title: Re: Can't get runtk to work?
Post by: cormullion on October 25, 2006, 12:40:46 PM
Quote from: "gcanyon"I'm trying to use runtk to call tk, and getting an error. Here's the error:



invalid function : (map set  '(myin tcout)   (pipe))




It works fine here. But I can generate a similar error to yours:


invalid function : (map?set? '(myin?tcout) ? (pipe))

if I copy the text straight from the web page without editing it. Otherwise I don't see any errors.



- did you use "Zap Gremlins"? (He said cryptically...)
Title:
Post by: gcanyon on October 26, 2006, 06:56:55 AM
If you've read the previous messages in this thread, you know Lutz admonished me for not using newLISP through Terminal. I've been doing it using Text Wrangler, which has a Run command that works nicely and puts the results into a separate window.



In response, I told Lutz that i preferred working out of Text Wrangler.



Well, apparently Lutz is a very powerful ninja, because when I got home last night I found that using newLISP from Text Wrangler no longer worked. I've restarted, and it doesn't help.



I just tried it through Terminal, and _that_ works just fine.



For those keeping score, it's now Lutz: 1, Geoff: 0. ;-)



(any ideas what might have broken newLISP in Text Wrangler?)
Title:
Post by: lisp on October 26, 2006, 07:48:18 AM
Any updates to either newlisp or text wrangler?
Title:
Post by: cormullion on October 26, 2006, 10:11:51 AM
Quote from: "gcanyon"If you've read the previous messages in this thread, you know Lutz admonished me for not using newLISP through Terminal.



For those keeping score, it's now Lutz: 1, Geoff: 0. ;-)


I thought he was just trying to help you by reminding you that running from a text editor has a few special 'issues' that you need to be aware of that the language's designer can't anticipate (there being too many editors...).  For example, file permissions, search paths and environment variables (does newLISP inherit the right ones?), location of files (where is that file running from? - check with (println (main-args) - a typical pathname is '/var/tmp/folders.501/Cleanup At Startup/runtk-183575187.105.lsp.command'!), supplying arguments, unicode in and out, stderr/stdin etc.. not seeing returned values because you didn't use a (println) statement. And so on. Sometimes trying things in the Terminal can help to pin down some of these issues, and help  others with different systems resolve them. I use BBEdit all the time unless I can't avoid using the terminal, and I've encountered many of these problems before!



A reminder: if I copy the following code from the web browser into a new TextWrangler window and run it:


#!/usr/bin/newlisp
(println  "hello world")
(exit)


it doesn't work: I get the message:


invalid function : (println  "hello world")

which would be inexplicable if I didn't already know that I've managed to copy some invisible non-breaking space HTML codes without noticing them. (Hence my reference to Zap Gremlins earlier...)



Your idea of running the swarm from within TextWrangler is a good one and works perfectly here (after checking the copy/paste operation...;-). This is using the latest version of MacOS X, TextWrangler, and newLISP.



Does a simple hello world program no longer work at all? Does it work with any other language (eg Perl, Ruby)? I'm happy to help, but there's not much information...





Cool swarming code, by the way, Fanda!
Title:
Post by: gcanyon on October 26, 2006, 10:35:24 AM
Quote from: "lisp"Any updates to either newlisp or text wrangler?


Nope.


Quote from: "cormullion"
Does a simple hello world program no longer work at all? Does it work with any other language (eg Perl, Ruby)? I'm happy to help, but there's not much information...


I'll try this when I get home today. Maybe I'm just committing some stupid mistake in my code, and Text Wrangler isn't alerting me to it. I had been using newLISP-tk, so running out of Text Wrangler is new, and as you pointed out, there are complications. This is probably just one of them.



As you suggest, I'll try a simple println to see if that works.


Quote from: "cormullion"I thought (Lutz) was just trying to help you by reminding you that running from a text editor has a few special 'issues' that you need to be aware of...


Fair enough -- I'm not upset or anything. Trying out newLISP is quite a shock coming from Revolution -- http://www.runrev.com.



With Revolution everything is taken care of for you. A complete beginner can follow any of a number of tutorials on the web and create a simple standalone application for three platforms in about ten minutes.



I'd say the difference is roughly the same as buying a car from a dealer and driving it off the lot, and buying a bunch of parts and trying to build the car from scratch ;-)



The end result, however, is a car that goes 100 miles per hour on a D-Cell battery, and converts to an airplane or a boat when needed. So it should be worth it to build the car.
Title:
Post by: cormullion on October 26, 2006, 11:32:58 AM
Revolution is certainly cool - I tried it for a while, and I'd certainly consider choosing it if I ever had to develop a cross-platform application with a user interface. (And if someone else paid for licenses :-))



newLISP is a very different animal, complementary more than similar in any way. I find it ideal for customizing applications and systems where you don't need much of an interface. Eg for system agents - //http://newlisper.blogspot.com/2006/10/agents-and-daemons.html. You wouldn't really want to do this with Revolution, I expect, unless it uses hardly any resources.



How about combining the two? A newLISP plugin for Revolution... There's a project for you........
Title:
Post by: gcanyon on October 26, 2006, 02:23:48 PM
Quote from: "cormullion"Revolution is certainly cool - I tried it for a while, and I'd certainly consider choosing it if I ever had to develop a cross-platform application with a user interface. (And if someone else paid for licenses :-))



newLISP is a very different animal, complementary more than similar in any way. I find it ideal for customizing applications and systems where you don't need much of an interface. Eg for system agents - //http://newlisper.blogspot.com/2006/10/agents-and-daemons.html. You wouldn't really want to do this with Revolution, I expect, unless it uses hardly any resources.



How about combining the two? A newLISP plugin for Revolution... There's a project for you........


I was actually discussing that just last night with a friend. Revolution can receive commands, so it would be possible to use it in much the same way runtk lets you use tk.



The licensing might be a headache -- I'd have to check with the owners of Revolution. Revolution's UI toolkit doen't include some things I'm looking for -- a table object, for starters. I think it would be difficult to make the integration work well. I'm not sure about that last, though. If TK works, Rev should as well.
Title:
Post by: HPW on October 26, 2006, 10:37:47 PM
QuotenewLISP is a very different animal, complementary more than similar in any way. I find it ideal for customizing applications and systems where you don't need much of an interface.


Using newLISP together with neobook, I use it also as a great tool for scripting an interface. When the revolution Xternals-SDK would allow to integrate newLISP.dll in the same way with direct callbacks etc. it would be a good choice for multiplatform applications. From my reading of their web-site, I am not sure if revolution is capable of running runtime-generated scripts (to allow newLISP to script it).



By the way: Whats the size of a minimal runrev-app for windows standalone? Is it small like newLISP? ;-)
Title: Sometimes it just takes time and perspective...
Post by: gcanyon on December 05, 2006, 12:55:52 AM
I've been away for over a month. I hadn't thought about newLISP much during that time. I happened to think of newLISP tonight, though, so I came here to the forum.



I re-read the suggestions here.



I opened TextWrangler. (Not TextMate)



I pasted in the runTK code.



I pasted in the swarm code.



I zapped gremlins. (is there a similar command in TextMate?)



I ran the code, and it worked. Just like that.



Guess it's time to start trying to build interfaces...
Title:
Post by: gcanyon on December 05, 2006, 01:00:11 AM
Quote from: "HPW"By the way: Whats the size of a minimal runrev-app for windows standalone? Is it small like newLISP? ;-)


Not so small. I don't know what the actual memory use is, but on disk the minimum is about 3MB I believe.



Revolution doesn't compile conditionally. There's one engine file, and everything is in it.  So everything gets built into a standalone.



That said, you can easily build a standalone that will load and execute raw Revolution stack files. Under those circumstances you can have the user install the engine once, and just load stack files for each "app" you want to run. Stack files start at about 8KB I think -- very small.
Title:
Post by: HPW on December 05, 2006, 01:56:14 AM
QuoteThere's one engine file, and everything is in it. So everything gets built into a standalone.


In the meantime I got more info.

So 'everything' does not get automaticly into the standalone.

I have read more stuff about externals in runrev.

Thinking about a calling-wrapper for newLISP let me think about embedding such a wrapper. Here is the discussion with the runrev developers:



http://forums.runrev.com/phpBB2/viewtopic.php?t=465
Title: Re: Sometimes it just takes time and perspective...
Post by: cormullion on December 05, 2006, 03:02:30 AM
Quote from: "gcanyon"I zapped gremlins. (is there a similar command in TextMate?)


Hi and welcome back geoff. My TextMate free trial finished so i can't find one for you. However, this simple newLISP script is a skeleton for a simple roll-your-own Zap Gremlins alternative that emerged recently:


#!/usr/bin/newlisp

(set 'file (open ((main-args) 2) "read"))

(define (in-range? n low high)
  (and (<= n high) (>= n low))) ; can't get angle brackets to work when posting code to this forum!!!!

(while (read-line file)
(dolist (c (explode (current-line)))
 (if
  (or
    (in-range? (char c) 32 128)  ; ascii
    (in-range? (char c) 9 10)   ; tab newline
    (in-range? (char c) 12 13)   ; f r
    (= (char c) (int "xbb"))   ; right double angles
    (= (char c) (int "x25ca"))  ; diamond
    (= (char c) (int "x2022"))  ; bullet
    (= (char c) (int "x201c"))  ; open double quotes
    (= (char c) (int "x201d"))  ; close double quotes
  )
  (print c)))
(println) ; because read-line swallows line endings
)
(exit)


This allows the user to customize which non-ASCII characters get zapped and which don't. So as it stands this allows certain odd Unicode characters through but eliminates others. Adjust to taste.





I'm not an expert, but I think that there are two related issues: Unicode and HTML. My web browser (Safari) sees a non-breaking space character (0xA0 -> UC2A0) in HTML posted on this forum (and other sites) and preserves it when I copy/paste - I can't see it but it often prevents newLISP code from running in an editor. On this forum, the nbsp's are inserted by the forum code, and the newsfeeds have them as well, generated by the same code, I suppose. The newLISP manual doesn't use nbsp's much but they do creep into code occasionally. So if copy/pasted code doesn't run and you think it should, check for odd characters first!