Page 1 of 1
newLISP game
Posted: Mon Oct 17, 2005 7:29 pm
by Fanda
Hello!
You can find a game called "Inversi" on my website:
http://www.volny.cz/fsodomka/newlisp/
Enjoy, Fanda
PS: If we had a newbie category in the newLISP contest, I would submit it :-)))
Posted: Mon Oct 17, 2005 11:32 pm
by pjot
Well done!!! Runs fine in Linux.
I like these type of games very much. Why not submit it as contribution for the contest after all?
Peter
Posted: Tue Oct 18, 2005 12:51 am
by Lutz
Excellent, runs fine on Mac OSX too
Lutz
Ps: look into examples/tcltk.lsp in the source distribution directory it shows you how to make newLISP/Tcl-Tk programs without the newlisp-tk shell, just with Tcl/Tlk installed on your system.
Posted: Tue Oct 18, 2005 7:02 pm
by Fanda
Lutz wrote:Ps: look into examples/tcltk.lsp in the source distribution directory it shows you how to make newLISP/Tcl-Tk programs without the newlisp-tk shell, just with Tcl/Tlk installed on your system.
I will check it out!
Fanda
Posted: Tue Oct 18, 2005 7:43 pm
by Lutz
Using the method in examples/tcltk.lsp your applications will come up much faster, because there is a lot of overhead in newlisp-tk you don't really need in a finished applications (like all the editor/code-browser/debugger code, which is loading and initializing itself).
Interaction between newLISP and Tc/Tk is also faster because they communicate via pipes instead of Tcp/Ip. On UNIX you just have to be sure that the 'wish' tk window shell is installed, which is default on at least the popular UNIX installs like LINUX and Mac OSX and Win32 if you install both Tcl and Tk.
Lutz
ps: you may also want to checkout
http://gtk-server.org/ which uses a similar way to communicate and does platform independent GUIs with a variety of scripting languages.
Posted: Wed Oct 19, 2005 2:31 pm
by Dmi
tcltk.lsp is very cool!
I just trying to do the same for subsequent newlisp:
Code: Select all
(map set '(myin nlout) (pipe))
(map set '(nlin myout) (pipe))
(process "newlisp" nlin nlout)
(set 'online true)
(write-line "(println \"Welcome...\")" myout)
(define (convers)
(while online
(read-buffer myin 'buf 65000)
(print buf "\n$ ")
(write-line (read-line) myout)))
looks working, but when I enter at the "$" prompt:
Code: Select all
$ (begin (println "start") (sleep 30) (println "end"))
I have immediate result for first println and have returned to the prompt.
If, after 30 seconds I press enter, I got the side effect of the second println, i.e.
Code: Select all
fortuna:root# newlisp l.lsp
newLISP v.8.7.0 on linux, execute 'newlisp -h' for more info.
> (convers)
Welcome...
"Welcome..."
$ (+ 3 5)
8
$ (begin (println "start") (sleep 30) (println "end"))
start
$
end
"end"
$
If subsequent newlisp will have command prompt, then I will got the ability to catch whole result.
But, as I think, the prompt is supressed because stdin/out aren't terminal line.
Can I suggest a newlisp option, that will work opposite to "-c", i.e. to turn the command prompt to "on" despite the newlisp started on the terminal or not (and to turn buffering off, of course)?
Posted: Wed Oct 19, 2005 9:33 pm
by Lutz
To suppress the side effect to:
(silent (println "start") (sleep 30) (println "end"))
and you may look into newlisp-tk.tcl to see how it done there
Lutz
Posted: Wed Oct 19, 2005 9:53 pm
by Dmi
Oh! Sorry for my english ;-)
I'm not about a side effect.
I'm about a way to capture all function output at once:
When started through pipes, underlaying newlisp instance doesn't show a prompt (">").
So, if upper-level instance request underlying one to start some time-prolonged function call, it will not be able to know is that function call already finished, or not.
Posted: Thu Oct 20, 2005 2:27 am
by Lutz
Implement some kine of protocol to recognize the end of output from newLISP. Turning on the prompt is dangerous because the line-feed '>' combination could just be part of the output, and when the context changes or in debug situations the prompt looks entirely different.
Let the piped newLISP process execute a loop i.e.:
Code: Select all
;; this loop runnning in the piped newLISP process
(while (set 'line (read-line))
(catch (eval-string line) 'result)
(println result "###EOT###")
)
Then the controlling program checks for "###EOT###" indicating the end of output coming back.
Lutz
Posted: Thu Oct 20, 2005 5:21 am
by Dmi
Thanks!
I like it :-)
Posted: Thu Oct 20, 2005 2:56 pm
by Dmi
Now I got self-wrapped newlisp shell (newlisp under newlisp's control).
But to completely imitate a newlisp-shell effect, I need some feature.
I run the following loop at underlying newlisp:
Code: Select all
(while (set 'PROTOCOL:line (read-line))
(catch (eval-string PROTOCOL:line) 'PROTOCOL:result)
(println PROTOCOL:result "\n###EOT###"))
It represents side effects pretty good. But also I want to output a result value as newlisp does i.e.:
now, when I use (println PROTOCOL:line) I got:
And so for other cases.
How can I format a symbol's contents to a newlisp-compatible source-code representation? (complement to "eval-string")
newLisp already have a function (source), that does similar, but more complex job.
Posted: Thu Oct 20, 2005 5:29 pm
by Lutz
Lookup the function 'source' in the manual. It works like 'save' but instead writing to a file it returns a string:
Code: Select all
newLISP v.8.7.0 on OSX, execute 'newlisp -h' for more info.
> (define (foo x y) (+ x y))
(lambda (x y) (+ x y))
> (source 'foo)
"(define (foo x y)\n (+ x y))\n\n"
>
lutz
Posted: Thu Oct 20, 2005 7:42 pm
by Dmi
I just have a look at the newlisp's source code. Now I know!
I just want an exact version of a 'string' function, but with
Code: Select all
printCell(cell , TRUE, (UINT)&strStream);
that you use in REPL in newlisp.c
instead of
Code: Select all
printCell(cell , FALSE, (UINT)&strStream);
that is in original 'string' implementation in nl-string.c
This (very small) piece of code will give newLisp an ability to wrap itself in a shell' that will be undistinguished from original newlisp...
Posted: Thu Oct 20, 2005 9:12 pm
by Lutz
This program more or less behaves like the 'real' thing:
Code: Select all
; shell - simulating the newLISP shell
;
(print "newLISP shell\n\n> ")
(while (set 'line (read-line))
(if (catch (eval-string line) 'result)
(if (string? result)
(println "\"" result "\"")
(println result))
(println result))
(print "> "))
Code: Select all
~/newlisp> newlisp shell
newLISP shell
> (print "abc")
abc"abc"
> (+ 3 4)
7
> (abc)
invalid function in function eval-string : (abc)
>
Lutz
Posted: Fri Oct 21, 2005 5:46 am
by Dmi
Hehehe :-)
printCell(TRUE) calls printString, that seems to do the more complex thing:
1. [text][/text] wrapping,
2. converting a bunch of special symbols to metacharacters (\n -> \\n etc.)
3. whatsoever you have in it now or place in it later.
Yes, I can recreate this behavior in newlisp level, but it's a dumb work, I think.
Manual exporting a printCell(TRUE) to newlisp language level is much more simple (i've tested it yesterday ;)
Is there are any obstacle against that for future releases?
Posted: Mon Oct 24, 2005 4:42 am
by Fanda
Lutz: 'tcltk.lsp' wasn't working on my Win32. Original version has:
Code: Select all
bind . <Destroy> {puts {(exit)}}
[/text])
I just added 'update idletask':
Code: Select all
bind . <Destroy> {puts {(exit)}}
update idletask
[/text])
Original wasn't responding - window didn't show up "done".
---------------
Is there any easy way how to do my favorite 'tk' function? How do I hide window from newlisp.exe?
Thank you, Fanda
Posted: Mon Oct 24, 2005 6:29 am
by Lutz
Thw 'tk' functon is just writing to the pipe 'myout' to Tcl/Tk when using tcltk.lsp
Code: Select all
(write-line "wm withdraw ." myout) ; hide the main window
get a Tcl/Tk reference, there is one here:
http://newlisp.org/downloads/TclTk/
Lutz
Posted: Mon Oct 24, 2005 6:59 am
by newdep
Its a very nice game for the contest !!
Regards, Norman.
Posted: Wed Oct 26, 2005 6:49 am
by Fanda
Inversi v. 1.1:
- bigger windows
- levels 2x2 and higher
- better look, faster drawing :)
Fanda
Posted: Wed Oct 26, 2005 9:03 pm
by newdep
hahaha great game..I manage it all the time to create the most strange but semetric figures but it a hard job to get a clean square ;-) nice nice!
Regards, Norman.
Posted: Wed Oct 26, 2005 11:25 pm
by pjot
Very good improvement, thank you! The concept of this game is elegant, and yet, the game is difficult to solve. Very nice!!!
Peter
Posted: Thu Oct 27, 2005 5:32 pm
by Fanda
Honestly... Concept of this game isn't mine. I played one that has 5x5 field. I couldn't solve it (only by accident), so I decided to make my own version where I can better see the field and can think about it more :-)
Later on, I added more levels ;-)
Fanda
Posted: Thu Oct 27, 2005 6:41 pm
by PaipoJim
Fanda wrote:Honestly... Concept of this game isn't mine. I played one that has 5x5 field. I couldn't solve it (only by accident), so I decided to make my own version where I can better see the field and can think about it more :-)
Later on, I added more levels ;-)
Fanda
Good for you! I can't solve the 5x5 even by accident. I'm sure there is some sort of standard strategy for it but every time I get down to 2 squares I get stuck.... :-(
I guess I'll have to console myself by appropriating some of your Tcl/Tk code tricks for my current project!
-