Arc Forumnew | comments | leaders | submitlogin
2 points by akkartik 3952 days ago | link | parent

You can see what your macro expands to:

  arc> (macex1 '(inl 1 '(1 2 3)))
  (in 1 quote (1 2 3))
That probably explains the error message. (Quotes expand to the symbol quote.)

So all you have to do is not quote your argument:

  arc> (inl 1 (1 2 3))
  t
As a general rule, however, try not to use a macro unless you have to. In this case there's a pure function that does what you want:

  arc> (pos 1 '(1 2 3))
  0
  arc> (pos 4 '(1 2 3))
  nil
(You can use pos in a conditional just like inl because it is guaranteed to only return nil if and only if the element doesn't exist.)

More info: http://arclanguage.github.io/ref/list.html#pos. As an exercise try implementing pos for yourself :) And feel free to ask us more questions! I hadn't realized there were questions at stack overflow. I'll try to hang out there, but there's really nothing off-topic here.



3 points by shader 3952 days ago | link

I think it might help to point out how the macro expands there:

  (inl 1 '(1 2 3))
is transformed by the reader to

  (inl 1 (quote (1 2 3)))
which is then macro expanded by

  `(in ,elt ,@lst)
where elt is bound to '1, and lst is bound to '(quote (1 2 3)). This means that when lst is spliced in, you get:

  '(in 1 quote (1 2 3))
As stated, the problem is largely the choice of macro instead of function. Macros are primarily useful to control evaluation; they do not evaluate their arguments by default. A macro will only let you work with the literal input, not their values. You can't (with arc) have your cake and eat it too; you can only work with either the syntax, or the values. You wouldn't be able to do something like:

  (let x '(1 2 3)
     (inl 1 x))
for instance, because it would attempt to treat the symbol 'x as if it were a list to be spliced, not the value of x. That's why you need a function, like pos.

-----