Interacting with lisp from a lispbuilder-sdl application

Discussion of Common Lisp

Interacting with lisp from a lispbuilder-sdl application

Postby lisjak » Sun Jun 28, 2009 4:14 pm

Hi!

I'm using SBCL 1.0.29 + lispbuilder-sdl on Mac OS X, trying to develop a (gui) lisp application. I want a cross-platform application with truetype font display of text + interactive graphics - I've gone through possibilities and found out that probably SDL is the best bet. I got the feeling that wxWidgets bindings aka wxCL and Qt bindings for lisp are in a very poor state... because my app will not be 'widget rich' (though a file opening dialog would be very helpful) I think SDL is probably the best. Any other opinions/success stories with other libraries?

The first problem I bumped into is interacting with lisp - I would like the user to be able to talk directly to the lisp from the GUI window - in the same way that one can talk to lisp in the terminal. Right now, the best solution I achieved is that I have an input 'field' in my application where I type in lisp code and when enter is pressed I call something like
Code: Select all
(eval (read-from-string *user-input*))

in my application and then display the result of 'eval' as the result. If the user makes an error like calling a function that doesn't exist, the debugger starts in the terminal and my application window is closed. I've learned I can handle debugger to some extent by
Code: Select all
(setf *debugger-hook* #'lisp-debugger)

where #'lisp-debugger is my function, however the result is displayed in the terminal and the application window is closed.

Excuse my n00bness (I've been learning lisp for 6 months) - but how could I include the complete comunication with the lisp within my graphical application (within my window)? How can I make sbcl to output to a string I can display on the screen, rather than in the terminal? In the final version of application I would have only the application window showing without the terminal running sbcl, so I would like to communicate with sbcl like I would in the terminal, from my application. Any advice?
lisjak
 
Posts: 4
Joined: Sun Jun 28, 2009 3:50 pm

Re: Interacting with lisp from a lispbuilder-sdl application

Postby gugamilare » Mon Jun 29, 2009 8:48 am

You can take a look at the source code of projects that used lispbuilder-sdl and see how they did it. For instance, bunny slayer.
gugamilare
 
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: Interacting with lisp from a lispbuilder-sdl application

Postby lisjak » Mon Jun 29, 2009 9:13 am

Oh, great! Studying the code right now - a lot to be learned. REPL inside the app is around 100 lines of code, nice.

Thanks!
lisjak
 
Posts: 4
Joined: Sun Jun 28, 2009 3:50 pm

Re: Interacting with lisp from a lispbuilder-sdl application

Postby Ramarren » Mon Jun 29, 2009 10:27 am

lisjak wrote:I'm using SBCL 1.0.29 + lispbuilder-sdl on Mac OS X, trying to develop a (gui) lisp application. I want a cross-platform application with truetype font display of text + interactive graphics - I've gone through possibilities and found out that probably SDL is the best bet. I got the feeling that wxWidgets bindings aka wxCL and Qt bindings for lisp are in a very poor state... because my app will not be 'widget rich' (though a file opening dialog would be very helpful) I think SDL is probably the best. Any other opinions/success stories with other libraries?


I tried implementing a gui on top of SDL once, years ago, soon after I learnt Lisp and on top of my own SDL binding, but gave up when I realized that guis are more complicated than I thought. I hope you have more success and publish your work somewhere.

That said, as gui libraries go there is cells-gtk based on GTK/Cairo and cells, which I have cleaned-up and tested on SBCL 1.0.29 on Linux and Mac OSX (at least with X11 GTK, it should be possible to use native ones, but I haven't tried that). I don't really have a success story, since after cleaning those up I realised I don't actually need a GUI, but you might want to check it out.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: Interacting with lisp from a lispbuilder-sdl application

Postby Paul Donnelly » Mon Jun 29, 2009 5:32 pm

lisjak wrote:The first problem I bumped into is interacting with lisp - I would like the user to be able to talk directly to the lisp from the GUI window - in the same way that one can talk to lisp in the terminal. Right now, the best solution I achieved is that I have an input 'field' in my application where I type in lisp code and when enter is pressed I call something like

A Quake-style terminal is certainly cool and useful, but don't forget you can start up a Swank server, connect SLIME to it, and hack on your program with the usual full environment. For anything involved, that's likely to be the more pleasant route. I say this based on experience with StumpWM, which does provide an eval prompt.
Paul Donnelly
 
Posts: 148
Joined: Wed Jul 30, 2008 11:26 pm

Re: Interacting with lisp from a lispbuilder-sdl application

Postby lisjak » Tue Jun 30, 2009 1:25 am

Paul Donnelly wrote:A Quake-style terminal is certainly cool and useful, but don't forget you can start up a Swank server, connect SLIME to it, and hack on your program with the usual full environment. For anything involved, that's likely to be the more pleasant route. I say this based on experience with StumpWM, which does provide an eval prompt.


A Quake style console is exactly what I had in mind - just enough to do some configurations or check some variables or functions from within the application. I've got it almost working now with the help of Bunnyslayer code.

Swank+slime is foreign to me - can't get myself to use emacs, though everybody says it's 'the-right-way-TM', so I wouldn't know how to use swank from my app. For now, a simple repl will do :)

Perhaps it would be nice to have some basic widget kit written in Lisp for the lispbuilder-sdl - buttons, sliders, labels, window frames (all rendered with sdl) with messages.

From C++ apps I'm used to the idea that everything should be a class, even if you use only one instance - just for the purpose of having private and public class members... does CL favour the same approach? Any easy internet resource on CLOS? Right now I have a bunch of global variables and functions...

Also, I'm having trouble getting lispbuilder-ttf to work on Mac OS X 10.4 - I've compiled the glue dylib by making a small change to the makefile, but 'asdf-install' complains it cannot load the dylib, even though I type in the path to the library. Anybody working with lispbuilder-ttf on Mac OS X?
lisjak
 
Posts: 4
Joined: Sun Jun 28, 2009 3:50 pm

Re: Interacting with lisp from a lispbuilder-sdl application

Postby Paul Donnelly » Tue Jun 30, 2009 4:31 am

lisjak wrote:Swank+slime is foreign to me - can't get myself to use emacs, though everybody says it's 'the-right-way-TM', so I wouldn't know how to use swank from my app. For now, a simple repl will do :)

Ouch. I wince every time I hear someone say this. Not that I don't think there couldn't be something better than SLIME. Just because copy/paste sure isn't it. What a PITA. What's the problem with Emacs? You can practically use it like Notepad (and you can, if you enable cua-mode).
lisjak wrote:From C++ apps I'm used to the idea that everything should be a class, even if you use only one instance - just for the purpose of having private and public class members... does CL favour the same approach?

Definitely not. CLOS doesn't even have private slots, because Lispers are inclined to trust whatever programmers come after them to use the intended API.

Just use classes where you think they will make the code simpler.
Paul Donnelly
 
Posts: 148
Joined: Wed Jul 30, 2008 11:26 pm

From C++ to CLOS

Postby nuntius » Tue Jun 30, 2009 7:56 am

lisjak wrote:From C++ apps I'm used to the idea that everything should be a class, even if you use only one instance - just for the purpose of having private and public class members... does CL favour the same approach? Any easy internet resource on CLOS? Right now I have a bunch of global variables and functions...


In CL, try using packages to organize "public/private" relationships. External symbols are part of the supported API; the rest are part of the internal API. The CLHS alludes to this usage. Of course, the programmer can always peek inside when need be, but such use is discouraged socially rather than by the compiler.
http://www.lispworks.com/documentation/ ... 1_aaba.htm

This takes some getting used to, but the end result is cleaner than C++'s scoping and privacy mechanisms. Take for instance C++'s (in hindsight known to be) horrible ADL rules; a template function calling operator+ might get any matching operator in any matching namespace, not necessarily one meant for the template's API. This contrasts with CL's generic functions where you can easily (defmethod api:f ...).

As for organizing data, yes classes and structs are good tools for organizing variables.

Here's perhaps the shortest useful intro to CLOS. http://eval.apply.googlepages.com/guide.html
Slightly longer: http://www.aiai.ed.ac.uk/~jeff/clos-guide.html
I would avoid any guide which advocates a macro wrapper for defclass; people tend to quickly outgrow such wrappers.
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Interacting with lisp from a lispbuilder-sdl application

Postby lisjak » Tue Jun 30, 2009 8:50 am

@nuntius: Thanks for these links - I see how CL's approach is different from C++'s.

Perhaps it would be good if there was a 'sticky thread' in this forum with various links to learning resources and popular common lisp libraries - while CLHS and CLiki provide a nice 'full menu' it's often more productive for beginners to look only at 'best dishes' first and explore from that...
lisjak
 
Posts: 4
Joined: Sun Jun 28, 2009 3:50 pm

Re: Interacting with lisp from a lispbuilder-sdl application

Postby findinglisp » Wed Jul 01, 2009 3:35 pm

Paul Donnelly wrote:CLOS doesn't even have private slots, because Lispers are inclined to trust whatever programmers come after them to use the intended API.


...and are inclined to distrust whatever programmers came before them to provide the API they require in the present moment. 8-)
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
findinglisp
 
Posts: 440
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron