|
From: Yves S. G. <you...@gm...> - 2012-04-25 21:04:41
|
Hi all, Still learning about Lisp and I have a few questions. 1. Are there any differences between CLISP and Clozure? If so, how substantial are they? Which one would be a good place to start for someone new? 2. Say I have a file hello_world.lisp. In that file I have the function print. How do I execute that function from the command line? $ clisp hello_world:print ? I'd appreciate your help. |
|
From: Sam S. <sd...@gn...> - 2012-04-25 23:08:07
|
> * Yves S. Garret <lbh...@tz...> [2012-04-25 17:04:33 -0400]: > > 1. Are there any differences between CLISP and Clozure? yes. > If so, how substantial are they? wrt ANSI CL compliance - probably minor. wrt extensions - probably pretty significant. > Which one would be a good place to start for someone new? either one is good enough. try both, see which feels right. > 2. Say I have a file hello_world.lisp. In that file I have the function > print. How do I execute that function from the command line? $ clisp > hello_world:print ? print is a standard ansi cl function. do not redefine it. $ clisp file loads file.fas or file.lisp or file. it means that it evaluates every form in it, one by one. there are many more details, please see http://clisp.org/impnotes/clisp.html -- Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000 http://www.childpsy.net/ http://ffii.org http://memri.org http://americancensorship.org http://truepeace.org Two psychics reading each other's minds will die from stack overflow. |
|
From: Pascal J. B. <pj...@in...> - 2012-04-25 23:24:32
|
"Yves S. Garret" <you...@gm...> writes:
> 1. Are there any differences between CLISP and Clozure? If so, how
> substantial are they? Which one would be a good place to start
> for someone new?
Both are good implementation to start with.
> 2. Say I have a file hello_world.lisp. In that file I have the
> function print. How do I execute that function from the command
> line? $ clisp hello_world:print ?
Depends on what's in this file exactly.
While the underline character seems to be more "portable" than the dash
for file names (eg. it's advised to use the following regexp for
maximally portable file names: /[A-Z0-9_]{1,8}\.[A-Z0-9_]{1,3}/), as a
lisper I prefer to use a dash in file names instead of an underline.
It's in the lisp style, and it's easier to type: just a key instead of
shift combination.
So, let's assume a file named hello-world.lisp, containing:
----(hello-world.lisp)--------------------------------------------------
(defun hw ()
(format t "~%Bonjour le monde !~%")
(values))
------------------------------------------------------------------------
then you can run it from the unix command line with:
$ clisp -norc -ansi -q -x '(progn (load "/tmp/hello-world.lisp" :verbose nil) (values))' -x '(hw)'
Bonjour le monde !
$
But one wonders why you would want to do that? I mean, call a lisp
function from the unix shell?
Either you are implementing a unix script in clisp, in which case you
should name your file hw, and edit it to contain:
----(hw)----------------------------------------------------------------
#!/usr/bin/clisp -q -ansi -norc
(defun hw ()
(format t "~%Bonjour le monde !~%")
(values))
(hw)
------------------------------------------------------------------------
$ chmod 755 hw
$ ./hw
Bonjour le monde !
$
or you are just writing lisp programs, and then you boot the lisp
environment and stay in it to work:
$ clisp
i i i i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I 8 8 8 8 8 o 8 8
I \ `+' / I 8 8 8 8 8 8
\ `-+-' / 8 8 8 ooooo 8oooo
`-__|__-' 8 8 8 8 8
| 8 o 8 8 o 8 8
------+------ ooooo 8oooooo ooo8ooo ooooo 8
Welcome to GNU CLISP 2.49+ (2010-07-17) <http://clisp.org/>
Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2010
Type :h and hit Enter for context help.
;; Loading file /home/pjb/.clisprc.lisp ...
[…]
;; Loaded file /home/pjb/.clisprc.lisp
C/USER[1]> (load "/tmp/hello-world.lisp")
;; Loading file /tmp/hello-world.lisp ...
;; Loaded file /tmp/hello-world.lisp
#P"/tmp/hello-world.lisp"
C/USER[2]> (hw)
Bonjour le monde !
C/USER[3]>
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
|
|
From: Sam S. <sd...@gn...> - 2012-04-26 00:31:55
|
> * Pascal J. Bourguignon <cw...@va...> [2012-04-26 01:24:23 +0200]: > > So, let's assume a file named hello-world.lisp, containing: > > ----(hello-world.lisp)-------------------------------------------------- > (defun hw () > (format t "~%Bonjour le monde !~%") > (values)) > ------------------------------------------------------------------------ > > then you can run it from the unix command line with: > > $ clisp -norc -ansi -q -x '(progn (load "/tmp/hello-world.lisp" :verbose nil) (values))' -x '(hw)' > > Bonjour le monde ! > $ just do clisp -i hello-world -x '(hw)' or append "(hw)" to the file and just do clisp hello-world -- Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000 http://www.childpsy.net/ http://camera.org http://mideasttruth.com http://www.PetitionOnline.com/tap12009/ http://pmw.org.il .ACMD setaloiv siht gnidaeR |
|
From: Yves S. G. <you...@gm...> - 2012-04-27 17:48:45
|
Hi, just curious. I ran the little hello world function that you've
described with and without the (values)) at the end. Without, I got a NIL
returned. With the (values)), I did not have that NIL returned. I would
like to know why this is happening?
I'm guessing that all functions in Lisp return something, even if it's a
null (you have "void" in C/C++ and Java). So, without the (values)), the
function by default returns the null. However, with the (values)), we are
returning that variable, which is not bound to anything, which is just a
blank if it's not bound to nothing. Am I correct? If not, please feel
free to explain.
On Wed, Apr 25, 2012 at 7:24 PM, Pascal J. Bourguignon <
pj...@in...> wrote:
> "Yves S. Garret" <you...@gm...> writes:
>
> > 1. Are there any differences between CLISP and Clozure? If so, how
> > substantial are they? Which one would be a good place to start
> > for someone new?
>
> Both are good implementation to start with.
>
>
> > 2. Say I have a file hello_world.lisp. In that file I have the
> > function print. How do I execute that function from the command
> > line? $ clisp hello_world:print ?
>
> Depends on what's in this file exactly.
>
> While the underline character seems to be more "portable" than the dash
> for file names (eg. it's advised to use the following regexp for
> maximally portable file names: /[A-Z0-9_]{1,8}\.[A-Z0-9_]{1,3}/), as a
> lisper I prefer to use a dash in file names instead of an underline.
> It's in the lisp style, and it's easier to type: just a key instead of
> shift combination.
>
> So, let's assume a file named hello-world.lisp, containing:
>
> ----(hello-world.lisp)--------------------------------------------------
> (defun hw ()
> (format t "~%Bonjour le monde !~%")
> (values))
> ------------------------------------------------------------------------
>
> then you can run it from the unix command line with:
>
> $ clisp -norc -ansi -q -x '(progn (load "/tmp/hello-world.lisp"
> :verbose nil) (values))' -x '(hw)'
>
> Bonjour le monde !
> $
>
>
> But one wonders why you would want to do that? I mean, call a lisp
> function from the unix shell?
>
>
>
> Either you are implementing a unix script in clisp, in which case you
> should name your file hw, and edit it to contain:
>
> ----(hw)----------------------------------------------------------------
> #!/usr/bin/clisp -q -ansi -norc
>
> (defun hw ()
> (format t "~%Bonjour le monde !~%")
> (values))
>
> (hw)
> ------------------------------------------------------------------------
>
> $ chmod 755 hw
> $ ./hw
>
> Bonjour le monde !
> $
>
>
> or you are just writing lisp programs, and then you boot the lisp
> environment and stay in it to work:
>
> $ clisp
> i i i i i i i ooooo o ooooooo ooooo ooooo
> I I I I I I I 8 8 8 8 8 o 8 8
> I \ `+' / I 8 8 8 8 8 8
> \ `-+-' / 8 8 8 ooooo 8oooo
> `-__|__-' 8 8 8 8 8
> | 8 o 8 8 o 8 8
> ------+------ ooooo 8oooooo ooo8ooo ooooo 8
>
> Welcome to GNU CLISP 2.49+ (2010-07-17) <http://clisp.org/>
>
> Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
> Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
> Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
> Copyright (c) Bruno Haible, Sam Steingold 1999-2000
> Copyright (c) Sam Steingold, Bruno Haible 2001-2010
>
> Type :h and hit Enter for context help.
>
> ;; Loading file /home/pjb/.clisprc.lisp ...
> […]
> ;; Loaded file /home/pjb/.clisprc.lisp
> C/USER[1]> (load "/tmp/hello-world.lisp")
> ;; Loading file /tmp/hello-world.lisp ...
> ;; Loaded file /tmp/hello-world.lisp
> #P"/tmp/hello-world.lisp"
> C/USER[2]> (hw)
>
> Bonjour le monde !
>
> C/USER[3]>
>
>
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> A bad day in () is better than a good day in {}.
>
|
|
From: Pascal J. B. <pj...@in...> - 2012-04-27 18:12:15
|
"Yves S. Garret" <you...@gm...> writes: > Hi, just curious. I ran the little hello world function that you've described with and without the > (values)) at the end. Without, I got a NIL returned. With the (values)), I did not have that NIL > returned. I would like to know why this is happening? > > I'm guessing that all functions in Lisp return something, even if it's a null (you have "void" in C/ > C++ and Java). So, without the (values)), the function by default returns the null. However, with > the (values)), we are returning that variable, which is not bound to anything, which is just a blank > if it's not bound to nothing. Am I correct? If not, please feel free to explain. There's no variable named values. There's a function named values, which returns a variable number of values: one of each argument. Therefore (values) returns no value, since it has no argument. A function doesn't return nil by default, it returns whatever its returning form returns. In this case if you remove the call to VALUES, it's FORMAT which returns only one value, nil, which are taken by the implicit PROGN which returns them, which are taken by the BLOCK <function-name> which returns them, which are taken by the LAMBDA implicit PROGN which returns them. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. |