SBCL oriented code examples

111 views
Skip to first unread message

linuxhooligan

unread,
Nov 15, 2010, 12:23:37 AM11/15/10
to Land of Lisp
Hi everyone.

Just slowly entering the world of Lisp and programming in general via
LOL -- this book has really captured my imagination with this language
and particularly this book.

QUESTION: how hard will it be to convert the CLISP oriented examples
in the book (past chapter 12 according to the book) to SBCL oriented
code?

I am certain that trying to figure out how SBCL does it will be a good
learning challenge but given that I am using emacs + slime to explore
the various examples, it seems like it would be nice to continue that
path.

Anyone look through the code samples enough to guesstimate how
difficult it would be to get them to work on SBCL past chapter 12?

Oh, and as a side point ...

... I would like to appologize ahead of time for all the newbie
knownothings like me coming on board and polluting the waters so to
speak. I can already imagine the horrible code that will be generated
out of sheer enthusiasm LOL has generated! Congrats to the author and
everyone that helped make this book a reality, I feel like a kid again
thinking about just what MIGHT be possible with this cool new tool at
my fingertips.

Ciaran

unread,
Nov 15, 2010, 2:38:11 AM11/15/10
to Land of Lisp
My next free evening, I'm working on hacking Chapter 13 to work in
SBCL (though I'm using usocket now which is a library). Based on past
experience, each instance of porting shouldn't take more than an
evenings hacking to figure out and get running.

For what it's worth, Chapter 13 seems to have only one function which
needs porting, the (serve) function. All the others work out fine.
Once I get a version I'm happy with, I'll post the code on my blog.
If you are doing the same, I'd be interested to see your solution :)

Ciaran

Icarium

unread,
Nov 25, 2010, 11:10:52 AM11/25/10
to Land of Lisp
Here is my adaption of chapter 13.

https://simon.a-oben.org/blog/?p=271

Maybe it helps someone.
If you find any errors please comment on the post. I won't read this
group regularly.

Best regards
Simon

Conrad

unread,
Nov 25, 2010, 9:09:31 PM11/25/10
to Land of Lisp
Thanks Simon:

I will try to have some SBCL specific resources on landoflisp.com at
some point- At that point I will see what's available and try to make
sure people are able to work 100% in SBCL when using the book... your
adaptation will be really helpful for this (and I will credit you of
course)

Alexandre Paes

unread,
Nov 27, 2010, 5:06:23 PM11/27/10
to Land of Lisp
Hi everyone,

Just got to chapter 13 and guess what i'm using sbcl as well. I
managed to get the code in the book to work without changes by adding
conditional definitions for sbcl to have the same functions that are
present in clisp. I thought about using usocket or some other thing
but decided to try it out in plain sbcl code.

Here's my sbcl specific additions:

#+sbcl
(defun socket-server (port)
(let ((socket (sb-bsd-sockets:make-inet-socket :stream :tcp)))
(when socket
(sb-bsd-sockets:socket-bind socket #(127 0 0 1) port)
(sb-bsd-sockets:socket-listen socket 1)
socket)))

#+sbcl
(defun socket-accept (socket)
(let ((connected-socket (sb-bsd-sockets:socket-accept socket)))
(sb-bsd-sockets:socket-make-stream connected-socket
:input t
:output t)))

#+sbcl
(defun socket-server-close (socket)
(sb-bsd-sockets:socket-close socket))


Cheers,

Alex

Alexandre Paes

unread,
Nov 27, 2010, 6:19:33 PM11/27/10
to Land of Lisp
Apparently my solution works but has a really critical flaw. The fact
is that for sb-bsd-socket-make-stream to work i first had to call sb-
bsd-sockets:socket-accept which does actually return a new socket
which doesn't get closed anywhere since i'm only returning it's stream
from my socket-accept function, this is of course unless sbcl is smart
enough to close the socket once it's stream is closed (at the end of
the with-open-stream form).

Guess i was too eager to create a working solution without changing
the original book code that i kinda messed up.

Cheers,

Alex
Reply all
Reply to author
Forward
0 new messages