newLISP game
newLISP game
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 :-)))
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 :-)))
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.
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.
tcltk.lsp is very cool!
I just trying to do the same for subsequent newlisp:
looks working, but when I enter at the "$" prompt:
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.
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)?
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)))
Code: Select all
$ (begin (println "start") (sleep 30) (println "end"))
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"
$
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)?
WBR, 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.
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.
WBR, Dmi
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.:
Then the controlling program checks for "###EOT###" indicating the end of output coming back.
Lutz
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###")
)
Lutz
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:
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.
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###"))
Code: Select all
> (set 'a "a\nb")
"a\nb"
Code: Select all
> (set 'a "a\nb")
a
b
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.
WBR, Dmi
Lookup the function 'source' in the manual. It works like 'save' but instead writing to a file it returns a string:
lutz
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"
>
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
that you use in REPL in newlisp.c
instead of
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...
I just want an exact version of a 'string' function, but with
Code: Select all
printCell(cell , TRUE, (UINT)&strStream);
instead of
Code: Select all
printCell(cell , FALSE, (UINT)&strStream);
This (very small) piece of code will give newLisp an ability to wrap itself in a shell' that will be undistinguished from original newlisp...
WBR, Dmi
This program more or less behaves like the 'real' thing:
Lutz
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)
>
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?
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?
WBR, Dmi
Lutz: 'tcltk.lsp' wasn't working on my Win32. Original version has:
I just added 'update idletask':
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
Code: Select all
bind . <Destroy> {puts {(exit)}}
[/text])
Code: Select all
bind . <Destroy> {puts {(exit)}}
update idletask
[/text])
---------------
Is there any easy way how to do my favorite 'tk' function? How do I hide window from newlisp.exe?
Thank you, Fanda
Thw 'tk' functon is just writing to the pipe 'myout' to Tcl/Tk when using tcltk.lsp
get a Tcl/Tk reference, there is one here: http://newlisp.org/downloads/TclTk/
Lutz
Code: Select all
(write-line "wm withdraw ." myout) ; hide the main window
Lutz
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.... :-(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
I guess I'll have to console myself by appropriating some of your Tcl/Tk code tricks for my current project!
-