Arc Forumnew | comments | leaders | submitlogin
2 points by croach 6062 days ago | link | parent

schtog,

jmatt explained why you are having trouble with the second parameter, essentially its a list and not a number like the '+' function is expecting. You could write your macro this way to expand the rest list into individual parameters to the '+' function:

  (mac meta (x . y) 
    `(+ ,x ,@y))
I think this macro works a bit more like you are expecting it to.


1 point by schtog 6062 days ago | link

  (mac meta (x . y) 
      `(pr ,x ,@y))
arc> (meta 1 2 3 4 5) 123451

still dont see why the 1 is repeated in the end.

-----

2 points by sacado 6061 days ago | link

Everything returns a value in arc, at least nil, or any other value. When you evaluate something through the REPL, the result is displayed. When you call 'pr, all the args are displayed, then the first arg is returned (then, displayed by the REPL). If you type, say

  (for i 1 10 (pr 1 2 3 4 5))
You will not see the 1 repeated on each iteration. It will print nil, though : that's the value returned by 'for.

-----

1 point by jmatt 6062 days ago | link

Check out the definition for pr on arcfn. http://www.arcfn.com/doc/io.html

Prints arguments using disp. Returns the first argument.

-----

1 point by tokipin 6061 days ago | link

here's a macro that prints them out more telligibly:

  (mac pr2 args
       (let l (len args)
         `(do
            (pr ,@(firstn (- l 1) args))
            ,(last args))))

-----