Arc Forumnew | comments | leaders | submitlogin
2 points by zck 3946 days ago | link | parent

>Sorry, I know this isn't Stack Overflow, but virtually no one follows the arc-lisp tag there, and I don't know anywhere else to post.

Don't worry about this. I'm happy whenever anyone's talking about Arc. I'd love to have the problem that people are posting too much here.

I've been confused by this issue too. There are two things here.

1. First, instead of using 'in, you can use 'pos:

    arc> (pos 1 '(1 2 3))
    0
2. Let's make your macro work anyway:

First, reproduce:

    arc> (inl 1 '(1 2 3))
    Error: "_quote: undefined;\n cannot reference undefined identifier"
Huh, it works if you use 'list:

    arc> (inl 1 (list 1 2 3))
    t
Or without 'list:

    arc> (inl 1 (1 2 3))
    t
This is interesting. Let's use 'macex1 to see what happens:

    arc> (macex1 '(inl 1 '(1 2 3)))
    (in 1 quote (1 2 3))
So the problem is that '(1 2 3) really is a list with two things in it: the symbol 'quote and the list (1 2 3). I'm a little bit uncomfortable with this explanation, but this seems to mean that you don't want to pass a quoted list into a macro, but unquoted. This is the way most macros are used, but I hesitate to make it a global rule. Some day I'll understand macros better.


1 point by akkartik 3946 days ago | link

  arc> (inl 1 (list 1 2 3))
  t
I wouldn't rely on that:

  arc> (inl list (list 1 2 3))
  t
  arc> (let x list
         (prn list)
         (inl list (list 1 2 3 4)))
  #<procedure: list>
  t
So you're actually searching a list that includes the function list.

"..you don't want to pass a quoted list into a macro, but unquoted. This is the way most macros are used, but I hesitate to make it a global rule."

The rule is, the arg is eval'd if it's eval'd in the expansion. (Since macros don't eval args, they eval the return value.)

  (mac foo (x) (cons 3 ,x))  ; will eval x
  (mac bar (x) (cons 3 ',x))  ; won't eval x

-----