newLISP game

Started by Fanda, October 17, 2005, 12:29:01 PM

Previous topic - Next topic

Fanda

Hello!

You can find a game called "Inversi" on my website:

http://www.volny.cz/fsodomka/newlisp/">http://www.volny.cz/fsodomka/newlisp/



Enjoy, Fanda



PS: If we had a newbie category in the newLISP contest, I would submit it :-)))

pjot

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

Lutz

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

Fanda

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

Lutz

#4
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/">http://gtk-server.org/ which uses a similar way to communicate and does platform independent GUIs with a variety of scripting languages.

Dmi

#5
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)?
WBR, Dmi

Lutz

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

Dmi

#7
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.
WBR, Dmi

Lutz

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

Dmi

#9
Thanks!

I like it :-)
WBR, Dmi

Dmi

#10
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.
WBR, Dmi

Lutz

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

Dmi

#12
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...
WBR, Dmi

Lutz

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

Dmi

#14
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?
WBR, Dmi