Re: find with XPath over file system

[email protected] Mon, 31 Jan 2005 23:58:46 -0800 (PST)
Newsgroups gmane.lisp.scheme.ssax-sxml
Message-ID <[email protected]>
> find with XPath over file system
> http://uucode.com/texts/xfind/index.html

That is quite neat!

> Actions (for example, printing file names) are executed after
> collecting files, not during tree traversal.

Why?


The converters (or transformers, whatever they are called) in sxpath
can be quite general. Any function node->nodelist should do.  So you
can print as you traverse. The last snippet in

http://sourceforge.net/mailarchive/forum.php?forum_id=599&viewmonth=200411&viewday=1&style=flat

can be a good example. Actually, it would be even better if we write
it as

((sxpath `(// (div 1)
	       ,(lambda (node . rest) (write (strings-of-node node))))) doc)


> There are some differences between the file system tree and the XML
> tree. At first, the paths /bin and ../../../../bin may point to the
> same directory, but they look different for users. At second, we can
> lazily walk from the base directory to the root and at the same time
> descent from the root. A special attention should be paid to a meeting
> point. But I decided to ignore it due to the first issue, so nodes
> from relative and absolute XPaths are never equal.

If both paths point within UFS, then taking stat() (or lstat) of both
and comparing stat.dev and stat.ino fields should tell if they are the
same. In UFS, the combination (stat.dev, stat.ino) is a unique
identifier. Things are quite more problematic for NFS-mounted (and
remounted) and foreign-mounted file systems.


> In my applications, I'd like to represent tree-like structures as the
> real Scheme lists to Guile. There are two issues here:
>
>  - structures are big enough. Making a full copy of data is overhead,
>    so I'd like to instantiate tree branches on demand.
>  - Scheme list functions such as car, cdr, for-each etc should
>    work on exposed data.
>
> It's impossible to satisfy the both requirements. The problem is that list
> functions check the type of arguments, but we have to use a custom type for
> lazy instantiation of internal data as Scheme data.

It is true that R5RS permits an implementation to do an implicit
`forcing' of a delayed computation -- although only Gambit (with a
special compilation flag) actually does that. But surely one can
accomplish `lazy' evaluation just by defining special functions like
fcar (to be a composition of car and force), fcdr, fnull, fmap,
ffor-each. Or may want to use the stream SRFI, 
	http://srfi.schemers.org/srfi-40/
	http://srfi.schemers.org/srfi-40/post-mail-archive/msg00006.html


	Cheers,
	Oleg


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl