Read data file containing fractional numbers?



On May 19 Richard Fateman wrote:



Didn't I just answer this? :)

Do a little editing on the data file.  There are many many editors, and 
some of them can do this with a few keystrokes.

Here you can do this, starting with the comma-separated file..

replace  newline with ],[

put data:  [[

at the beginning

delete  extra ,[
at the end.

If the data was produced by a program, you could of course have it do 
this extra stuff too.

RJF
---------------------------------------
Hi Richard,  
Thanks for the prompt reply. I actually was not
following the mailing list updates, since I am not
on the "bounce list" and just occasionally go in to
the archive to see what's new.

It is amazing to me that I submitted a question so 
closely related to something you had just replied to.

Anyway, since my needs are so specialized, I just wrote
a do loop massaging function I call flist, and it seems
to do the job so far:
-----------------------------------

 Maxima 5.24.0 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
                                  2011-05-19


(%i1) display2d:false$

(%i2) fdataL : read_nested_list ("mydata2.dat",comma);
(%o2) [[1,0],[2,[-1,\/,3]],[3,[-1,\/,2]],[4,[-3,\/,5]],[5,[-2,\/,3]]]

(%i3) load(flist);
(%o3) "c:/work2/flist.mac"

(%i4) flist (fdataL);
(%o4) [[1,0],[2,-1/3],[3,-1/2],[4,-3/5],[5,-2/3]]

(%i5) fundef (flist);

(%o5) flist(mylist):=block([rlist,%k,%pk,tempL,%j,%pj],rlist:[],
            for %k thru length(mylist) do
                (%pk:part(mylist,%k),tempL:[],
                 for %j thru length(%pk) do
                     (%pj:part(%pk,%j),
                      if listp(%pj)
                          then tempL:cons(part(%pj,1)/part(%pj,3),tempL)
                          else tempL:cons(%pj,tempL)),tempL:reverse(tempL),
                 rlist:cons(tempL,rlist)),reverse(rlist))

(%i6) printfile ("mydata2.dat")$
1,0
2,-1/3
3,-1/2
4,-3/5
5,-2/3

-------------------------------------------------

ted