Arc Forumnew | comments | leaders | submitlogin
Macro question
1 point by projectileboy 5926 days ago | 4 comments
Lisp noob macro question: I was working on a macro to enable a toy-ish version of classes, just to give some folks a feeling for what you can do with macros, and I found - as usual - that I don't what the hell I'm doing. When I try to define this macro:

(mac defclass (name attributes methods) `(def ,name (,@attributes) (let methodz (obj ,@methods) (fn (method . args) ((methodz method) args)))))

Arc gives me this:

Error: "map: expects type <proper list> as 2nd argument, given: (method . args); other arguments were: #<procedure:.../dev/arc2/ac.scm:209:14>"

Note, however, that the concrete def on which this macro is based works just fine:

(def make-point ((o x 0) (o y 0)) (let methods (obj get-x [+ x] get-y [+ y] set-x [= x (car _)] set-y [= y (car _)]) (fn (method . args) ((methods method) args))))

Thoughts? Advice? Any help would be greatly appreciated. Thanks everyone.



3 points by cchooper 5926 days ago | link

I tried it on Anarki and it worked fine.

  (mac defclass (name attributes methods) `(def ,name (,@attributes) (let methodz (obj ,@methods) (fn (method . args) ((methodz method) args)))))
  (defclass make-point ((o x 0) (o y 0))  (get-x [+ x] get-y [+ y] set-x [= x (car _)] set-y [= y (car _)]))
  (= point (make-point 3 4))
  (point 'get-y)
  => 4
BTW, you can change (,@attributes) to just ,attributes and it will work the same.

-----

3 points by cchooper 5926 days ago | link

I've tried it on Arc2 and am getting the same message as you. So this must be a bug in Arc2 that's been fixed on Anarki.

-----

3 points by almkglor 5926 days ago | link

The Arc2 quasiquote fails if any sublist is improper, i.e. a dotted list.

-----

1 point by projectileboy 5926 days ago | link

Thanks to you and to cchooper for the help. I hadn't thought to run against Anarki.

-----