New to lisp and file IO

Discussion of Common Lisp
Post Reply
samohtvii
Posts: 12
Joined: Thu Aug 23, 2012 11:49 pm

New to lisp and file IO

Post by samohtvii » Thu Aug 23, 2012 11:57 pm

Hi all,

I am quite new to LISP and i am having a few problems reading from a file.
I'm not quite sure what LISP is capable of so maybe there is an easier way around this question but i am looking to create a list tree:
e.g. ((Emu)(Dog Beaver))
Firstly I read that lisp can read that straight from a file and make a list using defparameter.
So i have
1 - (defparameter *s* (open animals))
Then i get kinda lost.
2 - (read *s*) ???

anyways any help would be great.

so far my file animals has "((Emu)(Dog Beaver))" or would i have to have the animals in order and then read into the list?

Thanks

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: New to lisp and file IO

Post by ramarren » Fri Aug 24, 2012 2:16 am

First, LISP is not a language, it is a family of languages. Common Lisp is one of the languages of this family, and I assume you are asking about that since this is a CL subforum, but you should be clear about the difference when writing.

The file chapter in Practical Common Lisp explains this. You should probably read at least some introductory chapters of that as well.

saulgoode
Posts: 45
Joined: Tue Dec 14, 2010 1:39 am

Re: New to lisp and file IO

Post by saulgoode » Fri Aug 24, 2012 7:53 am

samohtvii wrote: So i have
1 - (defparameter *s* (open animals))
Then i get kinda lost.
2 - (read *s*) ???
:
:

so far my file animals has "((Emu)(Dog Beaver))"
The effect of reading an expression from a file is basically equivalent to what you would obtain by quoting the expression.

(defparameter *s* '((Emu)(Dog Beaver)) )

*s* ==> ((EMU)(DOG BEAVER))
(car *s*) ==> (EMU)
(cadr *s*) ==> (DOG BEAVER)
(caar *s*) ==> EMU
(cadadr *s*) ==> BEAVER

Note: If you wish to retain the original case of the symbols, you should set your readtable appropriately.

Post Reply