From: ··········@my-dejanews.com
Subject: Need help with CLIPS
Date: 
Message-ID: <7e3kpo$aus$1@nnrp1.dejanews.com>
Hi, Am a biginner with CLIPS. I have a data file containing 4 numbers say
(INTEGERS), spaced out by tabs, how can I read the data in this file and thus
allocate a particular INTEGER to a particular variable? In essence, I want to
read a file. Can I use the (readline) function and if so, how? I don't know
how to use the 'logical name' associated with the (readline) function, i.e.
dont have examples.  Can anyone please show me how and also suggest if there
is another method for doing this? Any help provided would be greatly
appreciated. Thanx. Zulfi

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
From: Kent M Pitman
Subject: Re: Need help with CLIPS
Date: 
Message-ID: <sfw677ew3or.fsf@world.std.com>
··········@my-dejanews.com writes:

> Hi, Am a biginner with CLIPS. I have a data file containing 4 numbers say
> (INTEGERS), spaced out by tabs, how can I read the data in this file and thus
> allocate a particular INTEGER to a particular variable? In essence, I want to
> read a file. Can I use the (readline) function and if so, how? I don't know
> how to use the 'logical name' associated with the (readline) function, i.e.
> dont have examples.  Can anyone please show me how and also suggest if there
> is another method for doing this? Any help provided would be greatly
> appreciated. Thanx. Zulfi

(defun read-file-of-numbers (file)
  (with-open-file (stream file :direction :input)
    (loop for thing = (read stream nil nil)
          while thing
          collect thing)))

This definition is not sensitive to carriage returns or linefeeds.
It just assumes there is whitespace between each number and reads
all the numbers in a file.  If you need to read exactly a certain number
of integers, that's easy to do, too.  I'll let you look it up, though.

Note: the fact that the numbers are integers will be recognized by their
syntax.  If the file contained floats, this function would return floats.
Indeed, if the file contained symbols or lists, this would read them
as well.  READ is very general.

Good luck.