Arc Forumnew | comments | leaders | submitlogin
2 points by rntz 5410 days ago | link | parent

Actually, there is already a function 'fill-table - I don't know how I missed it - that does most of what's wanted.

    (def filltbl (tbl keys vals)
      (fill-table (or tbl (table)) (mappend list keys vals))))
However, I honestly don't think this is a useful or general enough function to go in arc.arc, especially as we already have 'fill-table, 'listtab, etc.

As for "creating a named table", er:

    (= foo (table)) ; I'm unclear on what's difficult about creating a table.


1 point by thaddeus 5410 days ago | link

I think the difficult part is passing in an arbitrary name to a function, for which the tables 'name' becomes set to, but I am just guessing that's what he wants...

and I agree I don't see a whole lot of need for the function to be part of the arc release..., since there are probably better ways to accomplish the same end result.... a good example of which is news.arc's storage of story records.

-----

1 point by fallintothis 5410 days ago | link

I think the difficult part is passing in an arbitrary name to a function, for which the tables 'name' becomes set to, but I am just guessing that's what he wants...

I rather doubt that's the issue, as it's easy to do with a macro.

  arc> (mac filltbl (tbl keys vals)
         `(= ,tbl (fill-table (table) (mappend list ,keys ,vals))))
  #3(tagged mac #<procedure: filltbl>)
  arc> (filltbl blah '(a b c) '(1 2 3))
  #hash((c . 3) (a . 1) (b . 2))
  arc> blah
  #hash((c . 3) (a . 1) (b . 2))

I think it's just a request for a convenience function to zip together a list of keys with a list of values into a table, since the existing methods for creating tables center around having alternating key/value pairs.

-----

1 point by thaddeus 5410 days ago | link

Agreed, it was only a wild guess given he was already given a good solution, yet...

   "Am I missing anything here?"
So I don't know what the deal is, but I don't plan to spend any time thinking about it :)

-----

1 point by adm 5399 days ago | link

only difficulty was creating a list of pairs which can be used an an arg for fill-table or listtab.

  (mappend list keys vals)
is precisely what I wanted. Sorry for the caused confusion.

-----