Arc Forumnew | comments | leaders | submitlogin
4 points by nex3 6138 days ago | link | parent

This is largely a library issue - Arc could certainly do with better support for string ops, regexen, and especially datetime manipulation. But here's what I came up with (note that date-days is pretty inaccurate most of the time):

  (def compact (seq) (keep ~empty seq))

  (def date-days (date)
    (+ (* 365 (date 'year))
       (* 30  (date 'month))
       (date 'day)))

  (def date- (d1 d2)
    (- (date-days d1) (date-days d2)))

  (def format-date (date)
    (string (pad (date 'year) 4 #\0) "-"
            (pad (date 'month) 2 #\0) "-"
            (pad (date 'day) 2 #\0)))

  (= str "
  2008.2.18
  2008--3--21
    2008/5/26
  2008_7_4
  
  ")

  (each date (map (fn (date)
                    (map [coerce _ 'int]
                         (compact:ssplit date [no (<= #\0 _ #\9)])))
                  (compact:ssplit str))
    (let the-date (obj year (date 0) month (date 1) day (date 2))
      (when (<= 0 (date- the-date (datetbl (seconds))) 7)
        (prn "***")
        (prn "*****")
        (prn "*******")
        (prn "\a  " (format-date the-date) " is a holiday!")
        (prn "*******")
        (prn "*****")
        (prn "***"))))


4 points by map 6137 days ago | link

Good work.

I think you've highlighted at least one gap in Arc's arsenal. Using Arc2:

  arc> (ssplit " foo bar ")
  Error: "reference to undefined identifier: _ssplit"
You needed to use ssplit, but Arc doesn't have it.

I don't think the importance of string ops should be underestimated. Strings ops are just as essential as numerical ops. A language that cannot effortlessly manipulate strings is a low-level language in my book. If people are supposed to be testing Arc by using it instead of the languages they were using, Arc needs string ops. Can't they be easily lifted from mzscheme?

Remember the thread on implementing Eliza in Lisp and Ruby? No one posted an Arc version.

-----

3 points by nex3 6137 days ago | link

Oh, sorry, I should have specified: I used Anarki-specific stuff in several places. Mostly the date-manipulation, but also ssplit (I actually hadn't realized that wasn't in arc2. Yikes). Using Anarki, it should work, though.

I totally agree that strings ops are important. If I recall, PG has also said something to this effect, so I wouldn't be surprised if more of them crop up in the next few releases.

-----