reading integers from a stream



If you are always reading the same file, then consider this function, in
lisp, which you may load in to maxima.

(defun $readnums_from_lll_server() 
  (let ((ans nil) (n 0))
    (with-open-file (s "/lll_server/lll_server.fifo")
    (loop while  (setf n (read s nil nil))do   ;; read until there are no
more numbers, when read will return nil
				(push n ans)))
    (cons '(mlist) (nreverse ans))))  ;;make a Maxima list by putting a
header on it.


Instead of seeking a more and more complicated solution, I hope this
encourages you to use a simple one.
RJF


 

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Fabrizio Caruso
> Sent: Thursday, September 20, 2007 9:11 AM
> To: van Nek
> Cc: maxima at math.utexas.edu
> Subject: Re: [Maxima] reading integers from a stream
> 
> Thanks
> 
> It could work but as you said it would not
> work in the next version of Maxima.
> 
> 
> So maybe I should find some other solution or
> simply give up for the moment using directories with
> capital letters when using files in Maxima.
> Hoping that the next version of Maxima allows
> reading integers from stream even those
> whose paths have capital letters.
> 
>    Thanks anyway
> 
>    Fabrizio
> 
> 
> On Thu, 20 Sep 2007, van Nek wrote:
> 
> > Hi Fabrizio,
> >
> > I checked on ubuntu that openr handles paths case sensitive.
> > parsetoken (which won't be in Maxima 5.14 anymore) uses the 
> Lisp parser, so perhaps it is
> > faster than parse_string.
> > I hope the below code can help you.
> >
> > Volker van Nek
> >
> > /home/volker/Work/myFile.txt:
> > 123 234 345
> > 456 567 678
> > 789 890 900
> >
> > (%i1) stream: openr("/home/volker/Work/myFile.txt");
> > (%o1) #<INPUT BUFFERED FILE-STREAM CHARACTER 
> /home/volker/Work/myFile.txt
> > @1>
> > (%i2) while ( stringp( line: readline(stream) ) ) do (
> > listOfStrings: split(line),
> > listOfNumbers: if stringp(listOfStrings[1]) then 
> map(parsetoken,listOfStrings) else [],
> > print(listOfNumbers) );
> > [123, 234, 345]
> > [456, 567, 678]
> > [789, 890, 900]
> > []
> > (%o2)                                done
> > (%i3) close(stream);
> > (%o3)                                true
> >
> >
> >
> > Am 20 Sep 2007 um 16:43 hat Fabrizio Caruso geschrieben:
> >
> >> It seems to work in a non-case-sensitive way.
> >>
> >> I am using Linux and the path has most of the times
> >> at leat one capital letter.
> >>
> >> If I do this
> >> 
> ?open(?"//home/caruso//Work//code//c++//ntl_server//lll_server
> //lll_server.fifo"),
> >> I get
> >>
> >> nonexistent directory: #P"/home/caruso/work/"
> >>
> >> Is there a solution?
> >>
> >>    Fabrizio
> >>
> >>
> >> On Thu, 20 Sep 2007, Richard Fateman wrote:
> >>
> >>>
> >>>
> >>>> -----Original Message-----
> >>> RJF:
> >>>> You may be able to read integers separated by new lines or by
> >>>> spaces by
> >>>> using lisp.
> >>>> Try foo:?open(filename);
> >>>>  ?read(foo); ?read(foo); ....
> >>>> Getting the filename in the right form, as a string, may 
> be tricky.
> >>>> RJF
> >>>>
> >>> Hint  ...  Try   foo:?open(?"c:\\temp\\numbers")    for example.
> >>>
> >> _______________________________________________
> >> Maxima mailing list
> >> Maxima at math.utexas.edu
> >> http://www.math.utexas.edu/mailman/listinfo/maxima
> >
> >
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>