newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Fanda on October 17, 2005, 12:29:01 PM

Title: newLISP game
Post by: Fanda on October 17, 2005, 12:29:01 PM
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 :-)))
Title:
Post by: pjot on October 17, 2005, 04:32:57 PM
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
Title:
Post by: Lutz on October 17, 2005, 05:51:45 PM
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.
Title:
Post by: Fanda on October 18, 2005, 12:02:10 PM
Quote from: "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.

I will check it out!



Fanda
Title:
Post by: Lutz on October 18, 2005, 12:43:19 PM
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.
Title:
Post by: Dmi on October 19, 2005, 07:31:25 AM
tcltk.lsp is very cool!

I just trying to do the same for subsequent newlisp:
(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:
$ (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.
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)?
Title:
Post by: Lutz on October 19, 2005, 02:33:25 PM
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
Title:
Post by: Dmi on October 19, 2005, 02:53:17 PM
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.
Title:
Post by: Lutz on October 19, 2005, 07:27:33 PM
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.:

;; 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
Title:
Post by: Dmi on October 19, 2005, 10:21:23 PM
Thanks!

I like it :-)
Title:
Post by: Dmi on October 20, 2005, 07:56:22 AM
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:
(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.:
> (set 'a "anb")
"anb"

now, when I use (println PROTOCOL:line) I got:
> (set 'a "anb")
a
b

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.
Title:
Post by: Lutz on October 20, 2005, 10:29:39 AM
Lookup the function 'source' in the manual. It works like 'save' but instead writing to a file it returns a string:



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


lutz
Title:
Post by: Dmi on October 20, 2005, 12:42:30 PM
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
printCell(cell , TRUE, (UINT)&strStream);
that you use in REPL in newlisp.c

instead of
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...
Title:
Post by: Lutz on October 20, 2005, 02:12:57 PM
This program more or less behaves like the 'real' thing:



; shell - simulating the newLISP shell
;
(print "newLISP shellnn> ")
(while (set 'line (read-line))
    (if (catch (eval-string line) 'result)
        (if (string? result)
            (println """ result """)
            (println result))
        (println result))
    (print "> "))



~/newlisp> newlisp shell
newLISP shell

> (print "abc")
abc"abc"
> (+ 3 4)
7
> (abc)
invalid function in function eval-string : (abc)
>


Lutz
Title:
Post by: Dmi on October 20, 2005, 10:46:52 PM
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?
Title:
Post by: Fanda on October 23, 2005, 09:42:10 PM
Lutz: 'tcltk.lsp' wasn't working on my Win32. Original version has:


bind . <Destroy> {puts {(exit)}}
[/text])


I just added 'update idletask':
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
Title:
Post by: Lutz on October 23, 2005, 11:29:29 PM
Thw 'tk' functon is just writing to the pipe 'myout' to Tcl/Tk when using tcltk.lsp

(write-line "wm withdraw ." myout)    ; hide the main window


get a Tcl/Tk reference, there is one here: http://newlisp.org/downloads/TclTk/



Lutz
Title:
Post by: newdep on October 23, 2005, 11:59:40 PM
Its a very nice game for the contest !!



Regards, Norman.
Title:
Post by: Fanda on October 25, 2005, 11:49:27 PM
Inversi v. 1.1:

- bigger windows

- levels 2x2 and higher

- better look, faster drawing :)



Fanda
Title:
Post by: newdep on October 26, 2005, 02:03:51 PM
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.
Title:
Post by: pjot on October 26, 2005, 04:25:23 PM
Very good improvement, thank you! The concept of this game is elegant, and yet, the game is difficult to solve. Very nice!!!



Peter
Title:
Post by: Fanda on October 27, 2005, 10:32:35 AM
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
Title:
Post by: PaipoJim on October 27, 2005, 11:41:29 AM
Quote from: "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


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!

-