Subject: [clisp-list] Read-from-string

From: Leonardo Bitsch <[email-masked]>
Date: Tue, 6 Feb 2001 17:28:32 -0200 (EDT)

Hi..a simple problem!
How can I use `read-from-string` to read the hole string and not only a
part of it? Here is what I have:
>(stef st ("(+ 2 3)(* 3 3)"))
>(read-from-string st)
(+ 2 3)
7

and I want this:
>(read-from-string st)
(+ 2 3)(* 3 3)

Thanks....
[]`s

____________________________________________________________
____________________________________________________________
Leonardo Bitsch
Graduação em Engenharia de Controle e Automação Industrial
Laboratório de Controle e Microinformática - LCMI
Universidade Federal de Santa Catarina - UFSC
Florianópolis - SC
____________________________________________________________
____________________________________________________________

---

From: Sam Steingold <[email-masked]>
Date: 06 Feb 2001 14:29:50 -0500

> * In message <[email-masked]>
> * On the subject of "[clisp-list] Read-from-string"
> * Sent on Tue, 6 Feb 2001 17:28:32 -0200 (EDT)
> * Honorable Leonardo Bitsch <[email-masked]> writes:
>

what kind of object do you want to get?

        (+ 2 3)(* 3 3)

is not a printed presentation of a Lisp object.
if you want a function which returns multiple values, you should do

        (values-list (string-tokens "(+ 2 3)(* 3 3)"))

where `string-tokens' is defined in CLOCC/PORT
(http://closs.sourceforge.net, clocc/src/port/ext.lisp):

(defun string-tokens (string &key (start 0) max)
  "Read from STRING repeatedly, starting with START, up to MAX tokens.
Return the list of objects read and the final index in STRING.
Binds `*package*' to the keyword package,
so that the bare symbols are read as keywords."
  (declare (type (or null fixnum) max) (type fixnum start))
  (do ((beg start) obj res (num 0 (1+ num))
       (*package* (find-package "KEYWORD")))
      ((and max (= max num)) (values (nreverse res) beg))
    (declare (fixnum beg num))
    (setf (values obj beg)
          (read-from-string string nil +eof+ :start beg))
    (if (eq obj +eof+)
        (return (values (nreverse res) beg))
        (push obj res))))

(you might find it beneficial to ask general lisp question on
news:comp.lang.lisp). 

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Let us remember that ours is a nation of lawyers and order.

---

From: Reini Urban <[email-masked]>
Date: Wed, 07 Feb 2001 18:18:53 +0100

Sam Steingold schrieb:
> > >(read-from-string "(+ 2 3)(* 3 3)")

I also help myself often by adding "(progn" at the front and putting ")" at
the 
end of the string before calling read-from-string with user strings, 
esp. when they should be eval'd.
but of course values are better.

-- 
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html