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

Ahhh... Thank you - I get it. I can totally see using hook for logging purposes and I can imagine a bunch of other uses for it too...

example:

(= mydata (fromjson "{\"first\":\"Edgar\",\"last\":\"Poe\",\"age\":\"23\",\"dob\":\"Jan 19 1809\"}"))

(= datatypes (obj "first" 'text "last" 'text "age" 'integer "dob" 'date))

(= mydatabase (table))

  arc> mydata
  #hash(("last" . "Poe") ("first" . "Edgar") ("age" . "23") ("dob" . "Jan 19 1809"))

  (defhook integer (val)
    (coerce val 'int))

  (defhook date (val)
    (upcase val))

  (def storedata (mydb typedb)
   (each field (keys mydb)
     (fill-table mydatabase 
        (list field (aif (hook typedb.field mydb.field) it mydb.field))))
    mydatabase)

  arc> (storedata mydata datatypes)
  #hash(("last" . "Poe") ("age" . 23) ("first" . "Edgar") ("dob" . "JAN 19 1809"))
It should have clicked in when I saw aif, but it didn't.