Arc Forumnew | comments | leaders | submit | cchooper's commentslogin
2 points by cchooper 6359 days ago | link | parent | on: Cant get tutorial hello webapp to work

These are known bugs that occur on Windows platforms. There are instructions for fixing them somewhere on the forum, but I can't find them. It has something to do with using forward slashes in path names instead of back slashes. So if you see something like this anywhere in the Arc source code:

  (= some-var "arc/logs/srv")
change it to

  (= some-var "arc\\logs\\srv")
Alternatively, switch to Anarki as jmatt suggested. That seems to be what most people use.

-----

4 points by jmatt 6359 days ago | link

I got arc2 to work on linux and windows initially through searching the forums and finding bugs. It was an interesting exercise but overall I'd recommend arkani. arkani has more bug fixes and all sorts of interesting code to look at and/or use.

-----

1 point by cchooper 6359 days ago | link | parent | on: Suggestion for two core features

The problem I see with the second one is:

  ('foo) x) == ((quote foo) x)
so there would be no way of telling if you were trying to do a list-ref.

-----

3 points by cchooper 6359 days ago | link | parent | on: Suggestion for two core features

1) Good point. I should have written

  (x!y!z)
  => (1 2 3 4 5 6 7 8 9)
Edit: not I shouldn't! The first way was right.

2) I don't think so. I can't see this is much different to having lists or hashes in functional place.

-----


You don't need to check that pow is less than zero in that last case.

  (def power (nbr pow)
    (if (is pow 0) 1
        (> pow 0)
	    (let acc nbr
    		(for x 1 (- pow 1)
        		(= acc (* acc nbr))) acc)
	(let acc 1
    	    (for x pow -1
		(= acc (/ acc nbr))) (/ acc 1.0))))

  (def power (nbr pow)
    (if (is pow 0) 
	    1
        (> pow 0)
	    (* nbr (power nbr (- pow 1)))
	(/ 1 (power nbr (* -1 pow)))))
Of course, if you want it to be really fast...

  (time (expt 234 34445)) => 101 msec.

-----

1 point by globalrev 6354 days ago | link

how can it be so much faster? its written in C or something? its built in the language somehow i guess, its not possible to recreate for me by writing a def?

-----

1 point by sacado 6354 days ago | link

It is probably written in C and does not check its args every time it is called. Basically, every time you call 'is, '<, '+, or any other primitive operation, it checks whether its arguments are numbers, then performs the operation. All these checks are useless since, within the body of your function, you know the type of your args are numbers, but you cannot avoid them anyway. Optimization will come, later :)

-----


Here are my results:

non-recursive: 13469 13610 13480 13098 13139 avg. 13360

recursive: 13199 13279 13249 13340 13329 avg. 13279

I also tried a tail-recursive version, which should be faster than simple recursive:

  (def power (nbr pow (o retval 1))
    (if (is pow 0)
            retval
        (> pow 0)
            (power nbr (- pow 1) (* nbr retval))
        (< pow 0)
            (power nbr (+ pow 1) (/ retval nbr))))
and I got this:

13450 13449 13449 12938 13139 avg. 13285

So it looks to me like MzScheme can optimise them all to be about equal.

Edit: actually, as Sacado pointed out, Arc expands for into a recursive function, so we're not really testing iteration.

-----

3 points by cchooper 6360 days ago | link | parent | on: Forum suggestions

Definitely agree about the text entry. It drives me crazy.

-----

4 points by cchooper 6360 days ago | link | parent | on: Learningcurve of LISP?

I've never heard anyone say that before. It sounds crazy to me.

Are you sure they weren't talking about keeping individual functions small?

-----

1 point by globalrev 6360 days ago | link

could be, not sure and have no link.

-----


They aren't ignored, they just don't do anything. for can take any number of arguments: the first is the symbol, the second the start value, the third the end value, and the rest are all the body of the loop. They all get executed in every iteration. For example:

(for x 0 6 (prn 2345) (prn 666) (= acc (/ acc 2))) acc)

produces

  23456
  666
  23456
  666
  23456
  666
  23456
  666
  23456
  666
  23456
  666
  23456
  666
  1/128

-----


In this case it's not causing a problem. You're allowed to give parameters whatever name you want, but if you name the parameter after the function then you can't call the function from within itself because the name will now refer to the argument.

So if you don't need to call the function recursively, there's no harm. It's just a bit confusing.

-----

3 points by cchooper 6360 days ago | link | parent | on: small problem: (def power (nbr power)...

You don't need to nest if expressions in Arc, you can do this:

  (if a b
      c d
      e f
      g)
For defining power, it's easier to use a recursive function:

  (def power (n p)
    (if (is p 0) 1
        (> p 0)  (* n (power n (- p 1)))
        (/ 1 (power n (* -1 p)))))
If you want to use for then the problem is indeed (for x 0 power -1). for only counts up, so (= acc (/ acc nbr)) never gets executed because 0 is already greater than power.

Instead, try counting the other way around:

  (for x power 0
    (= acc (/ acc nbr)))

-----

More