Arc Forumnew | comments | leaders | submitlogin
Hello web app broken again on Linux
3 points by lojic 6148 days ago | 6 comments
arc0 had a problem running the 'hello' web app on Linux that was fixed by a patch ( http://arclanguage.org/item?id=101 ) that modified the ensure-dir and date functions. I've since upgraded to arc1 so the problems with those functions reappeared.

What platform is Arc being developed on? I checked the man page for mkdir on Ubuntu and Mac OS X and I don't see a -f flag which is being used in ensure-dir.

Is it possible to fix the next release of Arc to work on Linux? I don't think this particular patch (see my comment below) is the best approach because of the overhead of (uname), but if Arc can detect the platform it's running on in a more efficient manner, then some conditional code could be put in place. Alternatively, I suppose uname could be memoized.



3 points by lojic 6148 days ago | link

Ok, here's the patch:

  --- arc1/arc.arc        2008-02-13 11:27:37.000000000 -0500
  +++ ../arc1/arc.arc     2008-02-23 21:14:50.000000000 -0500
  @@ -1195,11 +1195,24 @@
   
   (def ensure-dir (path)
     (unless (dir-exists path)
  -    (system (string "mkdir -f " path))))
  +    (system (string "mkdir -p " path))))
  +
  +(def uname nil 
  +  (let val (tostring (system "uname"))
  +  (cut val 0 (- (len val) 1))))
   
   (def date ((o time (seconds)))
  -  (let val (tostring (system (string "date -u -r " time " \"+%Y-%m-%d\"")))
  -    (cut val 0 (- (len val) 1))))
  +  (let val (tostring (system 
  +                      (string
  +                       "date -u "
  +                       (if 
  +                        (is (uname) "Linux")
  +                        ;; Linux wants -d and an interval
  +                        (string "-d \"" (- 1 (since time)) " seconds\"")
  +                        ;; BSD wants -r and epoch seconds
  +                        (string "-r " time))
  +                       " \"+%Y-%m-%d\"")))
  +     (cut val 0 (- (len val) 1))))
   
   (def count (test x)
     (with (n 0 testf (testify test))

-----

7 points by kens 6148 days ago | link

There was an earlier patch (first comment under http://arclanguage.org/item?id=155) that used mzscheme's date operators and avoided the platform-dependent system insanity. I advocate stamping out use of "system" from the Arc code, as it's almost guaranteed to break on different platforms. If mzscheme has taken care of platform dependence, Arc might as well take advantage of it.

As an aside, I notice that both the OpenID and "Arc at work" use system to do the heavy lifting. I propose a law that any sufficiently complicated Arc application requires use of "system" to get things done.

-----

7 points by almkglor 6146 days ago | link

kens' law: Any sufficiently complicated Arc application requries the use of 'system to get things done.

-----

3 points by lojic 6147 days ago | link

I was hoping that pg could simply put the fix in the arc source, so we don't have to keep patching with each release.

-----

1 point by sjs 6148 days ago | link

This code can be simplified a little bit:

    (let val (tostring (system 
                        (string "date -u "
                               (if  (is (uname) "Linux") "-r @" "-r ")
                               time " \"+%Y-%m-%d\"")))
But it's still fragile and non-portable so go with kens suggestion.

-----

2 points by nex3 6147 days ago | link

The patch for this was one of the first things added to Anarki.

-----