Arc Forumnew | comments | leaders | submitlogin
5 points by eds 6139 days ago | link | parent

First-class macros? Anyone?

If not the macros than more ergonomic error messages.



3 points by tokipin 6139 days ago | link

as a lisp noob i'm curious what specific sorts of things you could do with first-class macros. perhaps swapping out macros for a given macro call? say in one pass of a program (function) a particular macro call is expanded by macro1, and in the second pass the macro call is expanded by macro2

-----

6 points by kens1 6138 days ago | link

The problem I ran into today was:

  arc> (apply or '(nil t nil))
  Error: "Function call on inappropriate object #3(tagged mac #<procedure>) (nil t nil)"
I assume that first-class macros would let me do this.

-----

4 points by nex3 6139 days ago | link

There are folks here who know more about this than I do, but I think first-class macros would be very useful for creating a pure-Arc module system.

-----

2 points by eds 6138 days ago | link

I'm not exactly an expert on this, but I think it would allow you to put a macro literal in functional position. Right now:

  arc> and
  #3(tagged mac #<procedure>)
  arc> (eval (list and 1 nil 2))
  Error: "Bad object in expression #3(tagged mac #<procedure>)"
So if you had theoretical first-class macros, you could do stuff like use backquote to protect a macro you use from being overridden. (This wouldn't be necessary if we had a module system, but that might require first-class macros itself.) So in the (contrived) example below, foo works fine because prs is a function, but bar fails because foo is a macro.

EDIT: Actually, function literals in functional position only works on Anarki. It might be nice to have that fix in the official version.

  arc> (mac foo args `(,prs ,@args))
  #3(tagged mac #<procedure>)
  arc> (mac bar args `(,foo ,@(keep [isa _ 'sym] args)))
  #3(tagged mac #<procedure>)
I think first-class macros might be useful in making infix math expansion occur at compile time rather than run time... but I'm not completely sure on that one.

-----

4 points by Jesin 6137 days ago | link

Yes, please. First class macros and the ability to use macros and functions (rather than just their names or definitions) in functional position would be great, and macro names would not have to shadow variable names gobally anymore. In my opinion that is one of the biggest problems with Arc.

-----

2 points by sacado 6136 days ago | link

Oh, yes. That one drove me crazy a few times.

-----

1 point by nex3 6138 days ago | link

fns in functional position work fine for me in arc2... can you give an example where they die?

-----

3 points by eds 6138 days ago | link

  arc> (eval (list + 3 4))
  Error: "Bad object in expression #<procedure:...mming\\Arc\\ac.scm:602:9>"

  arc> (mac foo args `(,+ ,@args))
  #3(tagged mac #<procedure>)
  arc> (foo 3 4)
  Error: "Bad object in expression #<procedure:...mming\\Arc\\ac.scm:602:9>"

-----

1 point by nex3 6138 days ago | link

Oh, I thought you meant function literals as in calls to fn. But calling functions from lists... yeah, that would be great to have.

-----