• Re: reading-files. CLOS-support?

    From B. Pym@21:1/5 to Pete Halverson on Fri Sep 20 07:23:55 2024
    XPost: comp.lang.scheme

    Pete Halverson wrote:

    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 :-)

    Gauche Scheme:

    (use gauche.generator)

    (define (read-tokens-from-string string)
    (with-input-from-string string
    (cut generator->list read)))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)