Arc Forumnew | comments | leaders | submitlogin
1 point by bOR_ 5948 days ago | link | parent

I'll put in a bit more detail., hopefully enough. It might be that I indeed need a macro, but it could also be some oversight in me.

Given the function

  (def dot (g x y)
     (* (g 0) x) + (* (g 1) y))
(which evidently expects g to be a list, and x and y to be numbers), I get this error message when supplying it with variables.

dot((list 0 -1 1) 0.3 0.3) #<procedure: dot> arc> Error: "list-ref: expects type <non-negative exact integer> as 2nd argument, given: 0.3; other arguments were: (0 -1 1)"



3 points by rntz 5948 days ago | link

You can't use "foo(bar)" to call foo on bar in arc, you have to say "(foo bar)". Interpreting "dot((list 0 -1 1) 0.3 0.3)", Arc first evaluates 'dot (doing nothing) and then evaluates ((list 0 -1 1) 0.3 0.3), which calls the newly created list '(0 -1 1) on the two arguments 0.3 and 0.3, which in turn causes an error because it's trying to get the 0.3rd element from the list, which makes no sense. (Also it's been given two arguments when it expects only one.) This is a case of Arc not having very informative error messages.

Also, I think there's an error in the 'dot function, as you use a '+ where it will do nothing. Arc has no infix math, so what you want is something like this:

    (def dot (g x y)
      (+ (* (g 0) x) (* (g 1) y)))
    
    (dot (list 0 -1 1) 0.3 0.3)

-----

1 point by bOR_ 5948 days ago | link

arg. that's a silly error of mine. I translated the program from ruby, and that one must have slipped.

-----