Arc Forumnew | comments | leaders | submitlogin
Create your own collection in Arc: settable functions now implemented on arc-wiki.git
5 points by almkglor 5908 days ago | 2 comments
Hello all, I've implemented the settable-functions thingy on the arc-wiki.git.

To use, just require or load lib/settable-fn.arc

Now you can start building your own collection-like objects. It won't have amenities like (keys ...) and (ontable k v ...) and (len ....) yet, but I think it may be possible to extend the "attachment" concept further down that road if it becomes necessary.

  (= *test-settable-fn
   (let (x y) nil
    (add-attachment '=
      ;setterfunction
      (fn (v s)
        (case s
          x (= x v)
          y (= y v)
            (err:string "Disallowed key: " s)))
      ;readerfunction
      (fn (s)
        (case s
          x x
          y y)))))


3 points by nex3 5908 days ago | link

Very cool. I haven't gone over it in very much detail, but is there a reason you didn't use annotate/type/rep rather than Scheme vectors? It seems like it should be possible to do this in pure Arc...

-----

1 point by almkglor 5908 days ago | link

I wanted to retain annotate type information, so I decided to use a length-4 vector (annotate uses a length 3 vector). Also, by adding a hash in the 4th entry, we can attach even more keys to an object. For example, it would be possible to attach another function that returns the virtual "length" of the object, another function which returns the virtual "keys" of the object, and overload the basic functions (len ...) and (maptable ...) to use them.

-----