Arc Forumnew | comments | leaders | submitlogin
3 points by almkglor 5904 days ago | link | parent

Should be possible if you give a fully qualified path (file-table "/home/eds/somewhere")

Anyway it's probably better to figure out how Arc can get the fully qualified path from a path string, i.e. (get-fully-qualified-path ".") => "/home/eds/arc-installation/". Probably by ($ ...)

Unless you're referring to something else?

As for "other values".... the only real problem anyway is serialization. Ordinary Arc values that can be input into Arc via text are of course trivially serializable, but something created via:

  (= x (cons nil nil))
  (= y (cons x x))
  (= (cdr x) y)
is obviously not trivially serializable.


2 points by eds 5904 days ago | link

Yeah, (file-table "/home/eds/somewhere") is what I wanted, although having "." expand to `pwd` would be nice as well.

As for serialization, doesn't scheme have the ability to print circular objects? Not that that was really what I was thinking of.

Right now, all data that gets read from a file is in string form, so you have to explicitly

  (read ftab!fname)
to get an object stored in a file. Also, if you want to write an object like a list of strings to a file, you have to do something like

  (= ftab!fname (tostring (write '("hello," "world!"))))
to get the contents of the file to be readable.

Its not that serialization is difficult, but this seems like repetitive code that should be abstracted away. Maybe we should have one type/mode/version of file-table that reads everything as a string, and another that automatically prints a readable representation so that the object can be read back in later.

-----

3 points by almkglor 5904 days ago | link

Should be possible to abstract a layer around file-table for that (untested):

  (def file-table-w/read (path)
    (let ft (file-table path)
      (add-attachments
        '= (fn (v k)
             (= (ft k) (tostring (write v))))
        'keys (fn () (keys ft))
        (annotate 'table
          (fn (k) (read (ft k)))))))
Of course, the above doesn't memoize, so repeated calls to ftab!fname will return different ((iso ftb!fname ftb!fname) => t, (is ftb!fname ftb!fname) => nil) objects.

And of course, you're not supposed to write circular objects with the above.

And then someone will want to use temload and friends... hmm. Need a good way of abstracting the abstractions...

-----

2 points by eds 5903 days ago | link

Thanks. It might be nice to have that on Anarki.

EDIT: And it also might be nice to have the path parameter be optional (and default to ".").

-----

3 points by almkglor 5903 days ago | link

Hmm. What I'm currently planning is to have 'tofile and 'fromfile tagged arguments instead:

  (def file-table-w/read (path)
    (file-table path
                'tofile    [tostring (write _)]
                'fromfile  read))
Then memoization will be done on the file-contents (ct and mt) tables instead of actual file-table objects.

It would be useful also to have non-memoized versions, accessible via 'nocache:

  (def grep* (rex path)
    (zap re rex)
    (accum collect
      (ontable k v (file-table path 'nocache)
        (if (re-match rex v) (collect k)))))
'nocache would be useful for such cases where you want to scan through files but not cache their actual contents.

It might also be useful to store cached contents only for a certain time, to preserve memory (but then gc will get run anyway).

p.s. supporting tagged options will make an optional path argument difficult. I suppose I can check if the first argument is a string, though, and treat it as the path if it is.

-----