[Larceny-users] directory-files

Sven.Hartrumpf at FernUni-Hagen.de Sven.Hartrumpf at FernUni-Hagen.de
Thu Feb 8 05:15:03 EST 2007


Tue, 30 Jan 2007 17:36:12 -0500, felixluser wrote:

> On Jan 30, 2007, at 4:21 PM, Sven.Hartrumpf at FernUni-Hagen.de wrote:
>
> > Talking about OS specific functions, I need open-input-pipe
> > which seems to be a little more tricky (for performance reasons, I
> > cannot use the "file-trick" from above).
> > This is what I have so far:
> > (define open-input-pipe (lambda (command)
> >   (let ((results (process command))) ; format: (input output p-id)
> >     (car results))))
> >
> > process is defined in ./lib/Standard/unix.sch but I cannot use it:
> >> (require 'unix)
> >
> >
> > Error: Could not locate library: ffi
>
> Yes, this was broken in 0.93.  The directory paths and file names
> needed to be updated; see changeset:3807
>
> http://larceny.ccs.neu.edu/larceny-trac/changeset/3807

Thanks for the information Using the svn version, it Works now.
Please note that my code for open-input-pipe (above)
is problematic because it won't close processes cleanly.
The following avoids this problem:

(define call-with-input-pipe (lambda (command pred)
  (let* ((results (process command))
         (input-port (car results))
         (result (pred input-port)))
    (unix/wait) ; important in order to remove process
    result)))

Here is an example use:

(define directory-files (lambda (dir)
  (call-with-input-pipe (string-append "ls -1 " dir) read-lines-string)))

(define read-lines-string (lambda (input-stream)
  (let iter ((result '())
             (line (read-line-string input-stream)))
    (cond ((string? line)
            (iter (cons line result) (read-line-string input-stream)))
          (else
           (reverse! result))))))


Ciao
Sven
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://lists.ccs.neu.edu/pipermail/larceny-users/attachments/20070208/2baa1566/attachment.bin 


More information about the Larceny-users mailing list