On Sun, Feb 20, 2011 at 12:26 AM, Raul Miller <[email protected]> wrote: > On Sat, Feb 19, 2011 at 1:35 AM, Ric Sherlock <[email protected]> wrote: >> >> I'm interested in suggested improvements or alternative approaches. >> >> NB.*sayDiffNow v Phrase describing "length of time ago" >> NB. eg: sayDiffNow 0.02 >> NB. eg: sayDiffNow (6!:0'') daysDiff 2011 2 19 9 30 4.24 >> NB. y is: numeric number of days before "now" (day zero) >> sayDiffNow=: (3 : 0)"0 >> getidx=. 0 1r24 2r24 1 2 14 31 _&({.@I.@:>) >> msg=.'in the future';'less than an hour ago';' hour ago';' hours ago' >> msg=. msg,' day ago';' days ago';' weeks ago';'more than a month ago' >> msg=. msg {::~ getidx y >> time=. ,":<. empty`empty`(24&*)`(24&*)`]`]`(%&7)`[email protected] y >> time,msg >> ) > > I would be tempted to use > getidx=. (0 1r24 2r24 1 2 14 31 -9!:18'')&I. > I would also be tempted to use sprintf&>~ to build the message (putting %d > into the strings that need numeric arguments), and getting rid of "0 in the > function declaration. Then, rather than using a gerund, I could just select > a multiplier.
Thanks Raul, Yes my initial reaction was to use dyadic I. too, but how it handles bin cutoffs didn't fit this problem. I tried using slightly smaller cutoffs but gave them up as too inaccurate - your solution OTOH looks good. I'll investigate using sprintf. It would be nice to get rid of the gerund & "0. So far printf.ijs doesn't seem to have made it into j701 base library or addons so I'll need to sort that out first. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
