Arc Forumnew | comments | leaders | submitlogin
1 point by thaddeus 5653 days ago | link | parent

I'm not sure how any of these can work for intializing a table that's not aleady a table...

  (= k* '("1" "2" "3"))
  (= v* '("One" "Two" "Three"))

  assuming t* has not been set - this is what I get: 

  arc> (filltbl t* k* v*)
  Error: "reference to undefined identifier: _t*"
  
  or even:

  arc> (filltbl 't* k* v*)
  Error: "Can't set reference  t* \"1\" \"One\""

  so what am I missing ?


2 points by rntz 5653 days ago | link

filltbl isn't a macro, nor does it affect the global namespace. As written, it just creates a table if its first arg is nil. Of course, this is useless unless it returns that table... oops.

    (def filltbl (tbl keys vals)
      (or= tbl (table))
      (map (fn (k v) (= tbl.k v)) keys vals)
      tbl)
IMO, a more idiomatic way to represent this would be to use optional arguments, although that requires altering the argument order:

    (def filltbl (keys vals (o tbl (table)))
      (map (fn (k v) (= tbl.k v)) keys vals))
      tbl)

-----

1 point by thaddeus 5653 days ago | link

yeah I tried passing nil in, and got nothing back, so I figured it was supposed to create the table - I should have seen that too.

-----

1 point by adm 5653 days ago | link

Can this be part of arc.arc?

-----

1 point by shader 5652 days ago | link

You could push it onto Anarki. Other than that, there isn't much you can do to get it into a public arc.arc. It seems that if a function isn't used in the forum code, pg doesn't include it in the official release.

-----