Hi!
I am somewhat new to lisp. I am trying to develop interactive graphical
interface for engineering applications in lisp. I am using Xgcl developed
at UT Austin. I am running into innumerable problems. Could anyone of you
out there help me solve some of them?
First Installment:
I need to read an input file which is not written out as lists.
I can use read-line and get it as a string.
how do I convert this string to a list.
eg of kind of lines to be read and converted
Line 13.4 24 50 100.0 45.6 78
eye 0 0 0
aim -75 10 12
One posible solution I have is to coerce the string into a list
and reformulate the list by "imploding" atoms separated by blank spaces
together. This doesnt work for the number portion yet.But, I am still
working on it.
I have a HW due on Monday. I dont want to say it is not possible
in LISP and switch to C like the rest of my class. So, this is a real
emergency.
Thanks in advance
Priya
PS file format cannot be changed! user input!
______________________________________________________________________________
Whatever you can do or dream, begin it.
Boldness has genius, power and magic to it
GOETHE
From: Anders Vinjar
Subject: Re: reading-files. CLOS-support?
Date:
Message-ID: <46536c$c3p@hermod.uio.no>
["Priya (Kanaka priya Kalyanasundaram)" <·····@dopey.cc.utexas.edu>]:
> I need to read an input file which is not written out as lists.
> I can use read-line and get it as a string.
> how do I convert this string to a list.
> eg of kind of lines to be read and converted
> Line 13.4 24 50 100.0 45.6 78
> eye 0 0 0
> aim -75 10 12
> One posible solution I have is to coerce the string into a list
> and reformulate the list by "imploding" atoms separated by blank spaces
> together. This doesnt work for the number portion yet.But, I am still
> working on it.
Id be very interested in solutions to this as well. Id be happy to receive
duplicates of any email-messages showing up.
In particular, is there support in CLOS or any other CL OO-system to manage this
functionality in terms of generic methods?
--
Anders Vinjar
NICEM -
Norwegian Section of
International Confederation for Electroacoustic Music
In article <··········@hermod.uio.no>, Anders Vinjar
<········@notam.uio.no> wrote:
> ["Priya (Kanaka priya Kalyanasundaram)" <·····@dopey.cc.utexas.edu>]:
>
> > I need to read an input file which is not written out as lists.
> > I can use read-line and get it as a string.
> > how do I convert this string to a list.
> > eg of kind of lines to be read and converted
> > Line 13.4 24 50 100.0 45.6 78
> > eye 0 0 0
> > aim -75 10 12
> > One posible solution I have is to coerce the string into a list
> > and reformulate the list by "imploding" atoms separated by blank spaces
> > together. This doesnt work for the number portion yet.But, I am still
> > working on it.
>
> Id be very interested in solutions to this as well. Id be happy to receive
> duplicates of any email-messages showing up.
I would expect something as trivial as
(defconstant +EOF-MARKER+ (make-symbol "EOF"))
(defun READ-TOKENS-FROM-STRING (string)
(with-input-from-string (stream string)
(loop for thing = (read stream nil +eof-marker+)
until (eq thing +eof-marker+)
collect thing)))
ought to suffice here. (Apologies to loop haters; conversion to "Lisp" is
left as an exercise to the reader :-)
pch
In article <...> "Priya (Kanaka priya Kalyanasundaram)" <·····@dopey.cc.utexas.edu> write > First Installment:
> I need to read an input file which is not written out as lists.
> I can use read-line and get it as a string.
> how do I convert this string to a list.
> eg of kind of lines to be read and converted
> Line 13.4 24 50 100.0 45.6 78
> eye 0 0 0
> aim -75 10 12
Good luck with your project. Here's a bit of a solution to your
readline problem. It is in generic commonlisp:
(defun read-string-as-list (string)
(with-input-from-string (s string)
(loop for item = (read s nil nil)
while item
collect item)))
This uses the lisp reader (via READ) on each element of the line. The
collect creates and returns a list. You would use this function inside
the loop that reads lines from the file:
(with-open-file (input filename :direction :input)
(loop for line = (read-line input nil nil)
while line
collect (read-string-as-list line)))
This will give you a list for each line of the file. In your example
you would get
((LINE 13.4 24 50 100.0 45.6 78)
(EYE 0 0 0)
(AIM -75 10 12))
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu
In article <···············································@dopey.cc.utexas.edu> "Priya (Kanaka priya Kalyanasundaram)" <·····@dopey.cc.utexas.edu> writes:
> I need to read an input file which is not written out as lists.
> I can use read-line and get it as a string.
> how do I convert this string to a list.
Here's one way that should handle simple cases:
(defun read-line-as-list (&rest args)
(read-from-string (format nil "(~A)" (apply #'read-line args))))
You would use this as follows (where you type as input test 1 2 3.0):
> (read-line-as-list *standard-input*)
test 1 2 3.0
(test 1 2 3.0)
--
Peter Norvig | Phone: 415-833-4022 FAX: 415-833-4111
Harlequin Inc. | Email: ······@harlequin.com
1010 El Camino Real, #310 | http://www.harlequin.com
Menlo Park CA 94025 | http://www.cs.berkeley.edu/~russell/norvig.html