Hi,
I am working with clisp and this code below is not executing properly,
but it seems to execute properly in allegro. I am not understanding the
bug. I want to read from the filestream and print and evaluate the code
in it.
(defun execute-file (file-stream)
(let (line)
(loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
do (print line)
(eval line))))
Any help will be welcomed.
Thanks,
Surendra Singhi
In article <············@news.asu.edu>,
surendra <·········@netscape.net> wrote:
> Hi,
> I am working with clisp and this code below is not executing properly,
> but it seems to execute properly in allegro. I am not understanding the
> bug. I want to read from the filestream and print and evaluate the code
> in it.
>
> (defun execute-file (file-stream)
> (let (line)
> (loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
> do (print line)
> (eval line))))
>
> Any help will be welcomed.
I think CLISP only has CLtL's LOOP, not ANSI CL LOOP.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
How are they different?
Barry Margolin wrote:
> In article <············@news.asu.edu>,
> surendra <·········@netscape.net> wrote:
>
>
>>Hi,
>> I am working with clisp and this code below is not executing properly,
>>but it seems to execute properly in allegro. I am not understanding the
>>bug. I want to read from the filestream and print and evaluate the code
>>in it.
>>
>>(defun execute-file (file-stream)
>> (let (line)
>> (loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
>> do (print line)
>>(eval line))))
>>
>>Any help will be welcomed.
>
>
> I think CLISP only has CLtL's LOOP, not ANSI CL LOOP.
>
In article <············@news.asu.edu>,
surendra <·········@netscape.net> wrote:
>
> Barry Margolin wrote:
> > I think CLISP only has CLtL's LOOP, not ANSI CL LOOP.
> >
> How are they different?
The original LOOP didn't have any keywords, it just executed its body
repeatedly.
P.S. Please don't top-post.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
On Wed, 27 Oct 2004 23:59:56 -0400, Barry Margolin <······@alum.mit.edu> wrote:
> I think CLISP only has CLtL's LOOP, not ANSI CL LOOP.
No, it has full the full ANSI LOOP.
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
I don't understand your problem
with
c:\\data\\lisp\eval.lisp
(defun execute-file (file-stream)
(let (line)
(loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
do (print line)
(eval line))))
(defun test ()
(with-open-file (stream "c:\\data\\lisp\\test.data.cl" :direction :input)
(execute-file stream)))
#|
(test)
|#
and
test.data.cl being
(+ 3 4)
"works"
I get
T
[3]> (test)
t
(+ 3 4)
"works"
NIL
in clisp and
CL-USER(4):
(+ 3 4)
"works"
NIL
CL-USER(5):
in allegro
Seems to be fine, no?
"Edi Weitz" <········@agharta.de> wrote in message
··················@agharta.de...
> On Wed, 27 Oct 2004 23:59:56 -0400, Barry Margolin <······@alum.mit.edu>
> wrote:
>
>> I think CLISP only has CLtL's LOOP, not ANSI CL LOOP.
>
> No, it has full the full ANSI LOOP.
>
> Edi.
>
> --
>
> Lisp is not dead, it just smells funny.
>
> Real email: (replace (subseq ·········@agharta.de" 5) "edi")
On Wed, 27 Oct 2004 18:45:08 -0700, surendra <·········@netscape.net> wrote:
> I am working with clisp and this code below is not executing
> properly, but it seems to execute properly in allegro. I am not
> understanding the bug. I want to read from the filestream and print
> and evaluate the code in it.
>
> (defun execute-file (file-stream)
> (let (line)
> (loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
> do (print line)
> (eval line))))
Works fine here with 2.33.2 from Debian. You should post more
details. Why do you think it doesn't work? Do you have an example?
Which version of CLISP are you using?
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Sam Steingold
Subject: Re: clisp - eval function problem
Date:
Message-ID: <uu0semrlp.fsf@gnu.org>
> * surendra <·········@argfpncr.arg> [2004-10-27 18:45:08 -0700]:
>
> I am working with clisp and this code below is not executing
> properly, but it seems to execute properly in allegro.
what does "is not executing properly" mean?
<http://clisp.cons.org/faq.html#bugs>
> (defun execute-file (file-stream)
> (let (line)
> (loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
> do (print line)
> (eval line))))
this will read from stream until the end OR until symbol EOF.
try (load file-stream :print t)
--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
God had a deadline, so He wrote it all in Lisp.
Sam Steingold wrote:
>>* surendra <·········@argfpncr.arg> [2004-10-27 18:45:08 -0700]:
>>
>> I am working with clisp and this code below is not executing
>> properly, but it seems to execute properly in allegro.
>
>
> what does "is not executing properly" mean?
> <http://clisp.cons.org/faq.html#bugs>
Is there any clisp newsgroup?
>
>>(defun execute-file (file-stream)
>> (let (line)
>> (loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
>> do (print line)
>>(eval line))))
>
>
> this will read from stream until the end OR until symbol EOF.
>
> try (load file-stream :print t)
>
From: Sam Steingold
Subject: Re: clisp - eval function problem
Date:
Message-ID: <ubrelmzfp.fsf@gnu.org>
> * surendra <·········@argfpncr.arg> [2004-10-28 18:04:07 -0700]:
> Sam Steingold wrote:
>>>* surendra <·········@argfpncr.arg> [2004-10-27 18:45:08 -0700]:
>>> I am working with clisp and this code below is not executing
>>> properly, but it seems to execute properly in allegro.
>> what does "is not executing properly" mean?
>> <http://clisp.cons.org/faq.html#bugs>
> Is there any clisp newsgroup?
<http://clisp.cons.org/faq.html#bugs>
--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
If a train station is a place where a train stops, what's a workstation?
I figured out the problem. It wasn't an error in the read function or
even the "execute-file" function.
While calling the function i was using the ignore-errors:
"(ignore-errors (execute-file file-stream))"
and the file which I was trying to load had some errors in it causing
the read function to fail and return an error without printing anything.
The error was in the file was usage of #t instead of t.
The reason why it ran in allegro and not clisp. Look below.
Which is the true value recommended by the ANSi standard?
It seems clisp doesn't supports #t whereas allegro does.
Another interesting thing which I discovered about allegro is that while
it supports #t in the "cond" statement but if given just by itself
allegro evaluates it to nil.
Surendra Singhi
From: Matthew Danish
Subject: Re: clisp - eval function problem
Date:
Message-ID: <87y8hqrwyz.fsf@mapcar.org>
surendra <·········@netscape.net> writes:
> It seems clisp doesn't supports #t whereas allegro does.
#t is a Scheme thing. You are using Common Lisp. These are different
languages, get that clear in your head. Everything that is not NIL is
true, in Common Lisp. However, there is a value named T which is the
canonical true value.
--
;; Matthew Danish -- user: mrd domain: cmu.edu
;; OpenPGP public key: C24B6010 on keyring.debian.org
In article <············@news.asu.edu>,
surendra <·········@netscape.net> wrote:
> The error was in the file was usage of #t instead of t.
> The reason why it ran in allegro and not clisp. Look below.
>
> Which is the true value recommended by the ANSi standard?
#t is not specified at all in Common Lisp. You seem to be confusing CL
with Scheme. In CL, T is a constant that evaluates to T.
>
> It seems clisp doesn't supports #t whereas allegro does.
Sounds like an ACL extension.
>
> Another interesting thing which I discovered about allegro is that while
> it supports #t in the "cond" statement but if given just by itself
> allegro evaluates it to nil.
Very weird. What does '#t evaluate to?
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Barry Margolin wrote:
> In article <············@news.asu.edu>,
> surendra <·········@netscape.net> wrote:
>
>>The error was in the file was usage of #t instead of t.
>>The reason why it ran in allegro and not clisp. Look below.
>>
>>Which is the true value recommended by the ANSi standard?
>
>
> #t is not specified at all in Common Lisp. You seem to be confusing CL
> with Scheme. In CL, T is a constant that evaluates to T.
>
>
>>It seems clisp doesn't supports #t whereas allegro does.
>
>
> Sounds like an ACL extension.
>
>
>>Another interesting thing which I discovered about allegro is that while
>>it supports #t in the "cond" statement but if given just by itself
>>allegro evaluates it to nil.
>
>
> Very weird. What does '#t evaluate to?
>
in Allegro (ACL 6.2 trial edition) it evaluates to 'nil',
but it works like 't' when present in the cond statement.
Surendra Singhi
In article <············@news.asu.edu>,
surendra <·········@netscape.net> wrote:
> Barry Margolin wrote:
> > In article <············@news.asu.edu>,
> > surendra <·········@netscape.net> wrote:
> >
> >>The error was in the file was usage of #t instead of t.
> >>The reason why it ran in allegro and not clisp. Look below.
> >>
> >>Which is the true value recommended by the ANSi standard?
> >
> >
> > #t is not specified at all in Common Lisp. You seem to be confusing CL
> > with Scheme. In CL, T is a constant that evaluates to T.
> >
> >
> >>It seems clisp doesn't supports #t whereas allegro does.
> >
> >
> > Sounds like an ACL extension.
> >
> >
> >>Another interesting thing which I discovered about allegro is that while
> >>it supports #t in the "cond" statement but if given just by itself
> >>allegro evaluates it to nil.
> >
> >
> > Very weird. What does '#t evaluate to?
> >
>
> in Allegro (ACL 6.2 trial edition) it evaluates to 'nil',
> but it works like 't' when present in the cond statement.
I don't see how that can be. If you're correct, #t is translated to NIL
at read time. So by the time the compiler or interpreter processes the
COND form, there's no way it can tell that it originally had the #t
syntax.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
surendra <·········@netscape.net> writes:
> Hi,
> I am working with clisp and this code below is not executing
> properly, but it seems to execute properly in allegro. I am not
> understanding the bug. I want to read from the filestream and print
> and evaluate the code in it.
>
> (defun execute-file (file-stream)
> (let (line)
> (loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
> do (print line)
> (eval line))))
>
> Any help will be welcomed.
There's no reason why it should not work as it should.
CL-USER> (cat "surendra.test")
(+ 1 3)
(* 2 5)
(/ 33 12)
; No value
CL-USER> (with-open-file (in "surendra.test" :direction :input) (execute-file in))
(+ 1 3)
(* 2 5)
(/ 33 12)
NIL
CL-USER>
Also, you could implement it as:
(defun execute-file (file-stream) (load file-stream))
with some nice properties about some special variables (but perhaps
you want the possible side-effects).
Don't listen to those who spread FUD about clisp (or other lisp
implementation or Common-Lisp).
Note that READ doesn't read a line, it reads a full symbolic
expression (= s-expression = s-expr = sexp).
Your idiom for READ with EOF is wrong, because if there is a EOF
symbol present in the top level of the file, reading it will stop with
it. Perhaps that's what you wanted, but probably not. When you read
random s-expr files, you should use a GENSYMed symbol for EOF:
Note that most probably you'll want to print the result of EVAL too:
(defun execute-file (file-stream)
(loop with eof = (gensym)
for s-expr = (read file-stream nil eof)
until (eq s-expr eof)
do (print (eval (print s-expr)))))
CL-USER> (with-open-file (in "surendra.test" :direction :input) (execute-file in))
(+ 1 3)
4
(* 2 5)
10
(/ 33 12)
11/4
NIL
CL-USER>
--
__Pascal Bourguignon__ http://www.informatimago.com/
Voting Democrat or Republican is like choosing a cabin in the Titanic.
Pascal Bourguignon wrote:
> surendra <·········@netscape.net> writes:
>
>
>>Hi,
>> I am working with clisp and this code below is not executing
>>properly, but it seems to execute properly in allegro. I am not
>>understanding the bug. I want to read from the filestream and print
>>and evaluate the code in it.
>>
>>(defun execute-file (file-stream)
>> (let (line)
>> (loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
>> do (print line)
>>(eval line))))
>>
>>Any help will be welcomed.
>
>
> There's no reason why it should not work as it should.
>
> CL-USER> (cat "surendra.test")
> (+ 1 3)
> (* 2 5)
> (/ 33 12)
> ; No value
> CL-USER> (with-open-file (in "surendra.test" :direction :input) (execute-file in))
>
> (+ 1 3)
> (* 2 5)
> (/ 33 12)
> NIL
> CL-USER>
>
>
> Also, you could implement it as:
>
> (defun execute-file (file-stream) (load file-stream))
>
> with some nice properties about some special variables (but perhaps
> you want the possible side-effects).
>
>
> Don't listen to those who spread FUD about clisp (or other lisp
> implementation or Common-Lisp).
>
>
> Note that READ doesn't read a line, it reads a full symbolic
> expression (= s-expression = s-expr = sexp).
>
>
> Your idiom for READ with EOF is wrong, because if there is a EOF
> symbol present in the top level of the file, reading it will stop with
> it. Perhaps that's what you wanted, but probably not. When you read
> random s-expr files, you should use a GENSYMed symbol for EOF:
>
> Note that most probably you'll want to print the result of EVAL too:
>
> (defun execute-file (file-stream)
> (loop with eof = (gensym)
> for s-expr = (read file-stream nil eof)
> until (eq s-expr eof)
> do (print (eval (print s-expr)))))
I tried to write a code in a style similar to yours but it seems the
interpreter goes in an infinite loop of printing the first line. The
function read-line is not reading beyond the first line, am i making
some trivial mistake?
I am using clisp-2.33.1 on windows.
My code:
(defun print-on-printer (file-stream printer-stream)
(loop with line = (read-line file-stream nil 'eof) until (equal
line 'eof)
do (princ line printer-stream)
do (terpri printer-stream)))
Thanks,
Surendra
surendra <·········@netscape.net> writes:
> I tried to write a code in a style similar to yours but it seems the
> interpreter goes in an infinite loop of printing the first line. The
> function read-line is not reading beyond the first line, am i making
> some trivial mistake?
> I am using clisp-2.33.1 on windows.
> My code:
>
> (defun print-on-printer (file-stream printer-stream)
> (loop with line = (read-line file-stream nil 'eof) until (equal
> line 'eof)
> do (princ line printer-stream)
> do (terpri printer-stream)))
Read the loop chapter of CLHS!
http://www.lispworks.com/reference/HyperSpec/Body/m_loop.htm
http://www.lispworks.com/reference/HyperSpec/Body/06_a.htm
WITH is not FOR.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Voting Democrat or Republican is like choosing a cabin in the Titanic.
On 28 Oct 2004 21:03:20 +0200, Pascal Bourguignon wrote:
> Your idiom for READ with EOF is wrong, because if there is a EOF
> symbol present in the top level of the file, reading it will stop with
> it. Perhaps that's what you wanted, but probably not. When you read
> random s-expr files, you should use a GENSYMed symbol for EOF:
You can do that, but a nice alternative is to use the stream itself.
--
Succumb to natural tendencies. Be hateful and boring.
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(··@) "actrix.gen.nz>"))
Paul Foley wrote:
> On 28 Oct 2004 21:03:20 +0200, Pascal Bourguignon wrote:
>
>
>>Your idiom for READ with EOF is wrong, because if there is a EOF
>>symbol present in the top level of the file, reading it will stop with
>>it. Perhaps that's what you wanted, but probably not. When you read
>>random s-expr files, you should use a GENSYMed symbol for EOF:
>
>
> You can do that, but a nice alternative is to use the stream itself.
>
Can you please show me the alternative way of writing it?
Thanks.
On Thu, 28 Oct 2004 17:18:37 -0700, surendra wrote:
> Paul Foley wrote:
>> On 28 Oct 2004 21:03:20 +0200, Pascal Bourguignon wrote:
>>
>>> Your idiom for READ with EOF is wrong, because if there is a EOF
>>> symbol present in the top level of the file, reading it will stop with
>>> it. Perhaps that's what you wanted, but probably not. When you read
>>> random s-expr files, you should use a GENSYMed symbol for EOF:
>> You can do that, but a nice alternative is to use the stream itself.
>>
> Can you please show me the alternative way of writing it?
You have
(defun execute-file (file-stream)
(let (line)
(loop while (not (equal (setf line (read file-stream nil 'eof)) 'eof))
do (print line)
(eval line))))
but the symbol EOF could occur in the file. I'm saying you could just
replace 'eof with file-stream:
(defun execute-file (file-stream)
(let (line)
(loop while (not (equal (setf line (read file-stream nil file-stream)) file-stream))
do (print line)
(eval line))))
since the stream you're reading from won't occur in the file (unless
you go to some lengths to make that happen).
But you can write it in a cleaner way:
(defun execute-file (stream)
(loop for line = (read stream nil stream) until (eq line stream)
do (print line)
(eval line)))
--
Succumb to natural tendencies. Be hateful and boring.
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(··@) "actrix.gen.nz>"))