From: Michiel Borkent
Subject: CLISP newbie questions
Date: 
Message-ID: <c1lni8$h27$1@ares.cs.utwente.nl>
I have a few question on getting started in CLISP. I use it in Win2k.

I have a file called "prime.lisp" located in e:\clisp-2.23\mylisp. I start
CLISP with "clisp.bat" in e:\clisp-2.23.

I am able to run a program from the command prompt with "clisp.bat
prime.sieve".

There is a prime-sieve program in it and I run it with N=100, for example. I
get all prime numbers below 100 with:

(sieve 100)

I modified the program a bit, because I wanted to know the amount of prime
numbers below 100, so I put:

(length (sieve 100))

in the program. Now two questions:

-How do I get to print the result on screen?
-How do I load prime.lisp when I am at the CLISP prompt? I read
documentation but I couldn't find how to do this. And how can I reload a
program after editing it?
-Can I store the output of (sieve 100) in a variable, which I can use later
on? How?

I know these are beginners questions, but please help me a bit. You can also
e-mail me at:

borkent AT cs DOT utwente DOT nl

Gr,
Michiel

From: Kenny Tilton
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <PfD%b.24531$H17.14813@twister.nyc.rr.com>
Michiel Borkent wrote:
> -Can I store the output of (sieve 100) in a variable, which I can use later
> on? How?

Either:

  (defparameter *sieve-output* (sieve 100))
  (format t "~&Square of primes to 100 = ~d" (expt *sieve-output* 2))

or:

  (defvar *sieve-output*)
  (setq *sieve-output* (sieve 100))
  <same as above>

kenny

-- 
http://tilton-technology.com

Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film

Your Project Here! http://alu.cliki.net/Industry%20Application
From: John Thingstad
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <opr30px5moxfnb1n@news.chello.no>
On Thu, 26 Feb 2004 22:16:08 +0100, Michiel Borkent 
<·······@cs.utwente.nl> wrote:

> I have a few question on getting started in CLISP. I use it in Win2k.
>
> I have a file called "prime.lisp" located in e:\clisp-2.23\mylisp. I 
> start
> CLISP with "clisp.bat" in e:\clisp-2.23.
>
> I modified the program a bit, because I wanted to know the amount of 
> prime
> numbers below 100, so I put:
>
> (length (sieve 100))
>
> in the program. Now two questions:
>
> -How do I get to print the result on screen?
> -How do I load prime.lisp when I am at the CLISP prompt? I read
> documentation but I couldn't find how to do this. And how can I reload a
> program after editing it?
> -Can I store the output of (sieve 100) in a variable, which I can use 
> later
> on? How?
>

(load "prime.lisp)
(let ((prime-list (sieve 100))
     (format t "~&Number of primes: ~D~%~{~D~%~}" (length prime-list) 
prime-list))

~& means newline if not on a fresh line
~% means newline
~{ ~} means itterate over elements
~D means print decimal

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Michiel Borkent
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <c1n00l$mbe$1@ares.cs.utwente.nl>
Thanx a lot all! All the advised worked ok. Now I can get along further with
CLISP :)

Greetings,
Michiel
From: Michiel Borkent
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <c1n1nv$nqo$1@ares.cs.utwente.nl>
My next question would be:

Can I save a list (with prime numbers from the sieve) to a file, which I can
later on read and use the results in later calculations?

This way I wouldn't have to start the sieve over and over again from 2....

Gr,
Michiel
From: Chul-Woong Yang
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <ZnE%b.133394$S3.1523723@news.bora.net>
Michiel Borkent wrote:
> Can I save a list (with prime numbers from the sieve) to a file, which I can
> later on read and use the results in later calculations?

with-open-file macro and prin1/read will meet your purpose.

(defparameter *foo* '(foo bar))
(defun save-foo (l fname)
  (with-open-file (stream (make-pathname :name fname)
                          :direction :output)
    (prin1 l stream)))
(defmacro load-foo (l fname)
  `(with-open-file (stream (make-pathname :name ,fname)
                    :direction :input)
    (setf ,l (read stream))))

List elements should be readable, i.e. not hashtable,..
load-foo can be defun'ed, but then you may use (setf l (load-foo fname))
form, which is lisp style. But I prefer same interface for save & load.

Chul-Woong
From: Chul-Woong Yang
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <TpE%b.133396$S3.1523859@news.bora.net>
Michiel Borkent wrote:

> Can I save a list (with prime numbers from the sieve) to a file, which I can
> later on read and use the results in later calculations?

with-open-file macro and prin1/read will meet your purpose.

(defparameter *foo* '(foo bar))
(defun save-foo (l fname)
  (with-open-file (stream (make-pathname :name fname)
                          :direction :output)
    (prin1 l stream)))
(defmacro load-foo (l fname)
  `(with-open-file (stream (make-pathname :name ,fname)
                    :direction :input)
    (setf ,l (read stream))))

CL-USER> *foo*

(FOO BAR)
CL-USER> (save-foo *foo* "foo.data")

(FOO BAR)
CL-USER> (setf *foo* nil)

NIL
CL-USER> (load-foo *foo* "foo.data")

(FOO BAR)
CL-USER> *foo*

(FOO BAR)

List elements should be readable, i.e. not hashtable,..
load-foo can be defun'ed, but then you may use (setf l (load-foo fname))
form, which is lisp style. But I prefer same interface for save & load.

Chul-Woong
From: Pieter Breed
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <c1mscn$11d$1@ctb-nnrp2.saix.net>
Hi

I think the easiest way of working with your code is to copy the batch 
file to your code's location, and then run lisp from there. In other 
words make the working directory of lisp the same as where your code is.

the command to load an external .lisp file is quite simply:
(load "path/to/file.lisp")

in your case I presume: (load "prime.lisp")
just rerun this to reload the code.

As for your question about printing to screen, look at examples of 
(print) and (format). I am rather new myself and don't know the complete 
answers for these.

Hope this helps.

Pieter


Michiel Borkent wrote:
> I have a few question on getting started in CLISP. I use it in Win2k.
> 
> I have a file called "prime.lisp" located in e:\clisp-2.23\mylisp. I start
> CLISP with "clisp.bat" in e:\clisp-2.23.
> 
> I am able to run a program from the command prompt with "clisp.bat
> prime.sieve".
> 
> There is a prime-sieve program in it and I run it with N=100, for example. I
> get all prime numbers below 100 with:
> 
> (sieve 100)
> 
> I modified the program a bit, because I wanted to know the amount of prime
> numbers below 100, so I put:
> 
> (length (sieve 100))
> 
> in the program. Now two questions:
> 
> -How do I get to print the result on screen?
> -How do I load prime.lisp when I am at the CLISP prompt? I read
> documentation but I couldn't find how to do this. And how can I reload a
> program after editing it?
> -Can I store the output of (sieve 100) in a variable, which I can use later
> on? How?
> 
> I know these are beginners questions, but please help me a bit. You can also
> e-mail me at:
> 
> borkent AT cs DOT utwente DOT nl
> 
> Gr,
> Michiel
> 
> 
From: Pascal Bourguignon
Subject: Re: CLISP newbie questions
Date: 
Message-ID: <874qtc3k45.fsf@thalassa.informatimago.com>
"Michiel Borkent" <·······@cs.utwente.nl> writes:

> I have a few question on getting started in CLISP. I use it in Win2k.
> 
> I have a file called "prime.lisp" located in e:\clisp-2.23\mylisp. I start
> CLISP with "clisp.bat" in e:\clisp-2.23.
> 
> I am able to run a program from the command prompt with "clisp.bat
> prime.sieve".
> 
> There is a prime-sieve program in it and I run it with N=100, for example. I
> get all prime numbers below 100 with:
> 
> (sieve 100)
> 
> I modified the program a bit, because I wanted to know the amount of prime
> numbers below 100, so I put:
> 
> (length (sieve 100))
> 
> in the program. Now two questions:
> 
> -How do I get to print the result on screen?

Use print (or princ or format or write, etc)

    (format t "~&~A~%" (length (sieve 100)))


> -How do I load prime.lisp when I am at the CLISP prompt? I read
> documentation but I couldn't find how to do this. And how can I reload a
> program after editing it?

    (load "e:\\clisp-2.23\\mylisp\\prime.lisp")

or (in clisp):

    (ext:cd "e:\\clisp-2.23\\mylisp")
    (load "prime.lisp")


> -Can I store the output of (sieve 100) in a variable, which I can use later
> on? How?

1- declare a variable with:  (defvar primes-100)
2- assign to it with:        (setf primes-100 (sieve 100))

Note that  Common-Lisp stores automatically the last  three results in
variables named *, **, and ***. So you could type:

(sieve 100)
(length *)
(progn (princ *) (terpri))


> I know these are beginners questions, but please help me a bit. You can also
> e-mail me at:
> 
> borkent AT cs DOT utwente DOT nl
> 
> Gr,
> Michiel
> 
> 

-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/