What am I doing wrong

Discussion of Common Lisp
Post Reply
Mercfh
Posts: 17
Joined: Tue Mar 30, 2010 3:39 pm
Location: Miami,FL

What am I doing wrong

Post by Mercfh » Sat Apr 03, 2010 4:24 pm

I have a simple example readin function

Code: Select all

(defun read-setup (thefile)
(with-open-file (stream thefile)
    (loop for line = (read stream nil 'end)
          until (eq line 'end)           
          do (print (list (coerce line 'integer)
                            )     
              )     
     )
)
)
That just reads in some integers into a file, Im pretty sure it works, because it was an example in a e-book I have for lisp.

Im using clisp in ubuntu and I using the clisp -c Test.lisp and it says "compiled with 0 warnings and errors"
and it makes a Test.fas file. so I use ./Test.fas (after giving +x permissions)
and then it gives me the error
./Test.fas: line 1: syntax error near unexpected token `|'
./Test.fas: line 1: `(|SYSTEM|::|VERSION| '(20060802.))'

.....What am I doing wrong? im almost certain the code is right but i've never ran a lisp program before? It compiled with 0 errors and 0 warnings? So whats going on.....how do i run such a simple test code (btw I have a file called thefile)

Sorry for such a newbish question but this is my first time?

schoppenhauer
Posts: 99
Joined: Sat Jul 26, 2008 2:30 pm
Location: Germany
Contact:

Re: What am I doing wrong

Post by schoppenhauer » Sat Apr 03, 2010 5:44 pm

The .fas-File is a file containing code that can be loaded quickly - though, it is no executable. To execute it, use clisp -i <fas-file>. To really get an executable, you must load your file and generate an executable memory dump: http://clisp.cons.org/impnotes.html#image

Using

Code: Select all

(defun read-setup (thefile)
(with-open-file (stream thefile)
    (loop for line = (read stream nil 'end)
          until (eq line 'end)           
          do (print (list (coerce line 'integer)
                            )     
              )     
     )
)
)
(ext:saveinitmem "Test.mem" :executable T
	:init-function
	#'(lambda () (read-setup (car EXT:*ARGS*))))
(quit)
and loading the file with clisp -i (not -c) should do the job.
Sorry for my bad english.
Visit my blog http://blog.uxul.de/

Paul Donnelly
Posts: 148
Joined: Wed Jul 30, 2008 11:26 pm

Re: What am I doing wrong

Post by Paul Donnelly » Sat Apr 03, 2010 5:44 pm

Mercfh wrote:I have a simple example readin function

Code: Select all

(defun read-setup (thefile)
(with-open-file (stream thefile)
    (loop for line = (read stream nil 'end)
          until (eq line 'end)           
          do (print (list (coerce line 'integer))))))
That just reads in some integers into a file, Im pretty sure it works, because it was an example in a e-book I have for lisp.

Im using clisp in ubuntu and I using the clisp -c Test.lisp and it says "compiled with 0 warnings and errors"
and it makes a Test.fas file. so I use ./Test.fas (after giving +x permissions)
This is where you're going wrong. You must know some languages that like wasting your time by making you batch compile your program into an executable every time you just want to test a function, but since you're using Lisp you don't have to do this any more. Just type "clisp" to start up CLISP, and you'll land at a REPL where you can use the load function to load your code, then call your read-setup function. A transcript would look something like this:

Code: Select all

%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.48 (2009-07-28) <http://clisp.cons.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-2009

Type :h and hit Enter for context help.

;; Loading file /home/paul/.clisprc ...
;; Loaded file /home/paul/.clisprc
[1]> (load "Test")
;; Loading file /home/paul/Test.lisp ...
;; Loaded file /home/paul/Test.lisp
T
[2]> (read-setup "file
")

*** - OPEN: File 
#P"/home/paul/file
" does not exist
The following restarts are available:
ABORT          :R1      Abort main loop
Break 1 [3]> 
[4]> (read-setup "file")

(1) 
(3) 
(2) 
NIL
[5]> 
After you change the code, you can load the file again, or copy/paste the new defun directly into the REPL. CLISP has a comparatively usable REPL, with command-line editing and history, so it's not as painful as using some Lisps directly from the REPL would be. You'll have a more pleasant time all round if you set up SLIME, which will let you send new defuns to your lisp with a hotkey, among many other things.
Mercfh wrote:and then it gives me the error
./Test.fas: line 1: syntax error near unexpected token `|'
./Test.fas: line 1: `(|SYSTEM|::|VERSION| '(20060802.))'
I think what's happening is that your shell is trying to interpret Text.fas, which obviously isn't a bash script or whatever. That file is just a cache for CLISP's use, so when you load the source file it's derived from you won't have to recompile.

Piotr
Posts: 2
Joined: Fri Apr 02, 2010 8:05 pm
Location: Canada

Re: What am I doing wrong

Post by Piotr » Sat Apr 03, 2010 8:09 pm

You can also run it as a script using SBCL

Mercfh
Posts: 17
Joined: Tue Mar 30, 2010 3:39 pm
Location: Miami,FL

Re: What am I doing wrong

Post by Mercfh » Sat Apr 03, 2010 8:15 pm

Thanks alot everyone. I got the example code to work!

Post Reply