Maxima equivalent of ls



On June 14, Raymond Toy wrote:
--------------------------------
That's because cl:directory produces a Lisp list, not a Maxima list.
The main difference is that a Maxima list looks like '((mlist) l1 l2
l3 ...)

I think the easiest way would be to create your own Lisp function to
return a maxima list.  Something like:

:lisp (defun $directory (path) (list* '(mlist) (directory path)))

Then directory("foo") will return a normal Maxima list.

Note that cl:directory is notoriously implmentation-dependent; the
results can be very different depending on the Lisp being used.
------------------------------------------
Thanks for showing a method of converting
a lisp list to a Maxima list.

I have put your definition into directory.lisp
and the rest of the code into ls.mac.

Despite the Lisp version dependence of directory,
this code at least gives beginning string programmers
a starting point to test what happens with their lisp
version.

Using Windows (GCL) 5.24.0:
we test stripping off drive and folder
info using three different locations:
---------------------------------
(%i1) load("directory.lisp");
(%o1)                           directory.lisp
(%i2) load(ls);
(%o2)                           c:/work2/ls.mac

(%i3) ls("c:/line1*w.txt");
(%o3) [#pc:/line10w.txt, #pc:/line1b1w.txt, #pc:/line1b2w.txt,
                                             #pc:/line1bw.txt, 
#pc:/line1w.txt]

(%i4) dir("c:/line1*w.txt");
(%o4) [line10w.txt, line1b1w.txt, line1b2w.txt, line1bw.txt, line1w.txt]

(%i5) ls("c:/work2/line1*w.txt");
(%o5) [#pc:/work2/line10w.txt, #pc:/work2/line1b1w.txt,
        #pc:/work2/line1b2w.txt, #pc:/work2/line1bw.txt, 
#pc:/work2/line1w.txt]

(%i6) dir("c:/work2/line1*w.txt");
(%o6) [line10w.txt, line1b1w.txt, line1b2w.txt, line1bw.txt, line1w.txt]

(%i7) ls("c:/work2/temp1/line1*w.txt");
(%o7) [#pc:/work2/temp1/line10w.txt, #pc:/work2/temp1/line1b1w.txt,
#pc:/work2/temp1/line1b2w.txt, #pc:/work2/temp1/line1bw.txt,
#pc:/work2/temp1/line1w.txt]

(%i8) dir("c:/work2/temp1/line1*w.txt");
(%o8) [line10w.txt, line1b1w.txt, line1b2w.txt, line1bw.txt, line1w.txt]
-------------------------------------------------
with code in ls.mac:

ls(apath) := block ([%aL:[],%pL,%v],
             %pL : directory (apath),
             for %v in %pL do %aL : cons (%v,%aL),
             reverse(%aL))$

scut(%ds) :=
   block ([%dsr,%nrem],
     %dsr : sreverse (%ds),
     %nrem : slength(%ds) - (sposition ("/",%dsr) - 1),
     sreverse(simplode(rest(charlist(%dsr),-%nrem))))$

dir(apath) :=
      block ([%aL:[],%pL,%v],
         %pL : map ('string, ls(apath)),
         /* display (%pL), */
         for %v in %pL do
             %aL : cons (parse_string (scut(%v)),%aL),
         reverse(%aL))$
-------
and with directory.lisp containing:

;;; directory.lisp
;;; raymond toy code

(defun $directory (path) (list* '(mlist) (directory path)))

---------------------------------------------
Ted Woollett