Can't get runtk to work?

Started by gcanyon, October 24, 2006, 07:00:35 AM

Previous topic - Next topic

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



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.

Lutz

#1
Have you tried to run the programs without combining, as described here?

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



Lutz

gcanyon

#2
Quote from: "Lutz"Have you tried to run the programs without combining, as described here?

http://newlisp.org/index.cgi?Tips_and_Tricks">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

Lutz

#3
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

gcanyon

#4
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. ;-)

Fanda

#5
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

cormullion

#6
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...)

gcanyon

#7
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?)

lisp

#8
Any updates to either newlisp or text wrangler?

cormullion

#9
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!

gcanyon

#10
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">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.

cormullion

#11
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">//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........

gcanyon

#12
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">//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.

HPW

#13
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? ;-)
Hans-Peter

gcanyon

#14
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...