Arc Forumnew | comments | leaders | submit | thaddeus's commentslogin

I see. Thanks! T.

-----


hmm. I guess I could probably try 'w/appendfile' and not accum to a list...

-----

1 point by thaddeus 5917 days ago | link

nevermind :); w/outfile worked better.

-----

1 point by thaddeus 5918 days ago | link | parent | on: Ask Arc: inst or filltbl?

I think adm wants to create a named table. Correct me if I am wrong adm.

otherwise rntz's function, in the post, already returns a table:

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

-----

2 points by rntz 5918 days ago | link

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 5918 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 5918 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 5918 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 5907 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.

-----

1 point by thaddeus 5919 days ago | link | parent | on: Help: filltbl

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 5919 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 5919 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 5918 days ago | link

Can this be part of arc.arc?

-----

1 point by shader 5918 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.

-----


There are sooo many uses for these generic functions, I just need to get up to speed with all the possibilities...

thnx T.

-----


lol... that would have been nice to know :) thnx

-----

2 points by thaddeus 5922 days ago | link | parent | on: A noob's guide to web apps in arc

cool stuff... I was hoping at the end there would be a list of top scoring users.... oh well :)

on a side note: should your page title be thought, rather than though ?

A man, a though, a random coconut.

-----

1 point by coconutrandom 5920 days ago | link

Added and fixed. :)

hand->face for not seeing the typo

-----

1 point by thaddeus 5925 days ago | link | parent | on: I vote RTM to become super hacker spy

I read somewhere that rtm created the first worm ? I think that qualifies him for super spy hacker status. Certainly would meet the "colorful" criteria as suggested in the article.

I think rtm should apply and make arc the flagship tool....

All in fun :)

T.

-----


ah - i just commented out the whole thing and it's fixed.

Thanks for pointing me in the right direction.

-----


So I changed it to: (putenv "TZ" ":MDT")

now I get....

  arc>(system "date")
  Tue 23 Jun 2009 00:57:10 UTC

-----

1 point by CatDancer 5928 days ago | link

If you're going to set TZ, you need to set it to a valid TZ value, or else date is going to default to UTC.

http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html

But if you want it to use your normal system timezone, just don't set TZ.

-----

More