Arc Forumnew | comments | leaders | submitlogin
Create your own collection: proto-table, when you want prototyping semantics in your object system
4 points by almkglor 6002 days ago | 1 comment
Sometimes you want to build a table that is like, but not the same as, another table. You can copy the table element-by-element, but then you have the overhead of the copy (what if you just want to temporarily override a few keys?) and the table copy doesn't get updated if the base table is written to.

So yet again I now present a new collection type: the proto-table.

To use, just add a table to your call; you can even add keys in the call immediately:

  (require "lib/proto-table.arc")
  (= foo (table 'x 24 'y 25))
  (= bar (proto-table foo 'z 26 'x -1))
  bar!x
  => -1
  bar!y
  => 25
  bar!z
  => 26
  (= foo!y 1)
  bar!y
  => 1


7 points by almkglor 6002 days ago | link

The series of "create your own collection":

http://arclanguage.com/item?id=3595 Suggest PG: Settable function objects

http://arclanguage.com/item?id=3698 Create your own collection in Arc: settable functions now implemented on arc-wiki.git

http://arclanguage.com/item?id=3762 Create your own collection: use directories as if they were tables with file-table

http://arclanguage.com/item?id=3858 Create your own collection: bidirectional tables

http://arclanguage.com/item?id=5254 Create your own collection: cached-table

http://arclanguage.com/item?id=7365 Create your own collection: proto-table, when you want prototyping semantics in your object system

-----