From: N.
Subject: How to load and clear files?
Date: 
Message-ID: <1144617581.624892.311460@e56g2000cwe.googlegroups.com>
I am using GNU Common Lisp (http://clisp.cons.org/).


I have some files stoed of my local drive as a.lsp, b.lsp and c.lsp

I want to Lisp interpreter to load these files though the read-eval-
print loop and not though command line parameter (i.e clips a.lsp
when I start my lisp system). How do I go doing it?

Further I have some lists stored in text files (say x.list, y.list ...)
and I want to assign variable X and variable Y to the contents of
files x.list and y.list also from the read-eval-print prompt. How
should I do it?

And lastly, I want to clear all functions and variable definations.
What is the command to do it?

Thanks in advance,

N.

From: ·············@gmail.com
Subject: Re: How to load and clear files?
Date: 
Message-ID: <1144621120.618595.137750@t31g2000cwb.googlegroups.com>
>I want to Lisp interpreter to load these files though the read-eval-
>print loop and not though command line parameter (i.e clips a.lsp
>when I start my lisp system). How do I go doing it?

(load "a.lsp"), if that's what you mean.

>Further I have some lists stored in text files (say x.list, y.list ...)
>and I want to assign variable X and variable Y to the contents of
>files x.list and y.list also from the read-eval-print prompt. How
>should I do it?

http://mypage.iu.edu/~colallen/lp/node62.html (File I/O in Lisp).

If you want to assign it just to the contents...(setf x (with-open-file
(infile "x.list") (read infile))) should work (untested).
From: Pascal Bourguignon
Subject: Re: How to load and clear files?
Date: 
Message-ID: <87ek0673tg.fsf@thalassa.informatimago.com>
"N." <··········@gmail.com> writes:
> And lastly, I want to clear all functions and variable definations.
> What is the command to do it?

(do-symbols (s)
    (when (fboundp s) (ignore-errors (fmakunbound s)))
    (when (boundp  s) (ignore-errors (makunbound s)))) ; have fun!

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
From: arnuld
Subject: Re: How to load and clear files?
Date: 
Message-ID: <1144663011.017845.304000@v46g2000cwv.googlegroups.com>
I think you have got your answer from Pascal. still there is one more
thing i want to mention:

> I am using GNU Common Lisp (http://clisp.cons.org/).

it is not GNU Common Lisp. It is CLISP (http://clisp.cons.org/).

GNU Common Lisp is entirely different product.

-- arnuld
From: N.
Subject: Re: How to load and clear files?
Date: 
Message-ID: <1144786841.400153.97260@u72g2000cwu.googlegroups.com>
Thanks for your help guys!

I just have another question regarding CLISP and GNU Common Lisp. There
is a version
which compiles your lisp code into portable C code which can be
compiled on any
machine.

Which one if that? (CLISP/GNU Commom Lisp)

Further I have the file "a.lsp" with functions definations and a query
-say (fun 3 4),
which I want to be compiled into C code where main is the query (fun 3
4), what
command do I use?

Thanks again in advance,

N.



arnuld wrote:
> I think you have got your answer from Pascal. still there is one more
> thing i want to mention:
>
> > I am using GNU Common Lisp (http://clisp.cons.org/).
>
> it is not GNU Common Lisp. It is CLISP (http://clisp.cons.org/).
> 
> GNU Common Lisp is entirely different product.
> 
> -- arnuld
From: Pascal Bourguignon
Subject: Re: How to load and clear files?
Date: 
Message-ID: <87irpflo87.fsf@thalassa.informatimago.com>
"N." <··········@gmail.com> writes:

> Thanks for your help guys!

Now, reading your Subject: (which I don't usually do, but since you're
changing of subject...), which is quite different from what you asked
in your message, perhaps this answer will be more useful:

- usually, you don't need to "clear" the definitions you've loaded.
  You can just load new definitions to replace the old ones.  and if
  you have renamed a function, well, you still have the old function,
  by the old name in the lisp image, but it doesn't matter much.
  
  Well, it can lead to some errors, if you still use the old name
  somewhere, and you don't understand why the corrected version
  doesn't seem to be taken into account.  From time to time, I just
  quit lisp, relaunch it, and reload my program to make sure the files
  contain all what is needed to build the program and to make sure the
  lisp image contains only what's in the files.

- you can use packages to somewhat flush quickly your definitions.  If
  all you load go to your own package, when you want to "clear" it,
  you can just DELETE-PACKAGE your package, then reload your files
  that will re-create your package and fill it.  You can still have
  some references to the symbols in the old package, but now they're
  homeless and print as #:SYMBOLS, and if you load again the code that
  refer them it'll refer to the new one. (That's why we should load
  files depending on some other files _after_ the other files).
  
- finally, I should mention methods, in particular methods with
  :before, :after  or, :around qualifiers, IIAC.

   (defmethod m1 :after ((self my-class)) (print :hello))
   (defmethod m1 :after ((self my-class)) (print :world))

  this doesn't redefine the m1 method, it adds _two_ new methods after
  the m1 method.  Calling (m1 (make-instance 'my-class)) will print
  both :HELLO and :WORLD.

  AFAIK, there's no standard way to remove a method other than
  (FMAKUNBOUND 'm1) and redefine all the m1 methods, but there's a way
  using MOP. (Search googlegroups for more info).

  So if you're adding such qualified methods on standard generic
  functions, the easiest way to "clear" them is to quit and relaunch
  lisp.



> I just have another question regarding CLISP and GNU Common Lisp. There
> is a version
> which compiles your lisp code into portable C code which can be
> compiled on any
> machine.
>
> Which one if that? (CLISP/GNU Commom Lisp)

GNU Common Lisp, aka. gcl uses gcc as back-end compiler.  I wouldn't
call that portable C code, but since gcc works on almost any machine,
gcl should work on almost any machine too.

CLISP is written in portable C code: you can compile it on almost any
machine. Notably, it can be compiled with gcc and some other compilers
(eg. Microsoft Visual C).


> Further I have the file "a.lsp" with functions definations and a
> query -say (fun 3 4), which I want to be compiled into C code where
> main is the query (fun 3 4), what command do I use?

It depends on your implementation. 
First, there's not really a notion of main in lisp.

Top level forms may be evaluated when you load the file, or when you
compile the file.  But nothing is said of what to do with them when
you load a compiled file, or when you run an executable generated in
some way.

First, you could use EVAL-WHEN with :COMPILE-TOPLEVEL, LOAD-TOPLEVEL
or :EXECUTE to precise your idea.  But this still won't help for
executables. 


In the case of CLISP, when you save an executable image, or a simple
image, you can specify a function to be called when the image is
loaded: 

;; See: http://clisp.cons.org/impnotes/image.html

(defun main ()
   ...)

(EXT:SAVEINITMEM "mypgm"
                 :EXECUTABLE T #| or NIL |#
                 :INIT-FUNCTION (function main)
                 ...)


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Logiciels libres : nourris au code source sans farine animale."