probcomp / Venturecxx

Primary implementation of the Venture probabilistic programming system
http://probcomp.csail.mit.edu/venture/
GNU General Public License v3.0
28 stars 6 forks source link

Eval should evaluate the same language that the top level does #556

Open axch opened 8 years ago

axch commented 8 years ago

In order to do so, it must expand macros in its argument, which causes trouble because macro expansion is currently associated with

Status quo is that eval evaluates the post-macro-expansion language, which is pretty annoying when trying to write program-generating programs as @luac is doing for the inverse compilation paper.

Status quo is somewhat papered over by the fact that quote does not suppress macro expansion (though quasiquote effectively does #76), so (eval (quote .....)) looks reasonable, but this is not really a solution.

Independently, after fixing this and making quote suppress macro expansion the way it should (which may fix #295 also), if it turns out that we actually want the current behavior of quote, we can give that thing another name.

Options:

axch commented 8 years ago

Given that eval doesn't report errors all that well anyway (#562), option 2 above looks like the way to go.

axch commented 8 years ago

This definition of eval will be difficult to port to Puma, because the latter would need to either replicate or call out to the macro expander, which is written in Python. I am inclined to just break Puma's eval, possibly renaming it to eval_no_macros or something (and possibly also renaming the eval currently in Lite to the same, to retain compatibility in the Puma->Lite direction).

axch commented 8 years ago

Alternative: Provide smart expression constructors that do the macro expansion themselves as the expression is built. In other words, instead of writing (list 'if p c a) and relying on eval to expand the macros, write (if_form p c a) and rely on if_form to produce an output in the detailed syntax eval will understand.

It might even be possible to write a version of quasiquote that will do that conversion, so that (quasiquote (if (foo? ,p) (,c bar) ,a)) would expand into (if_form (app_form (ref_form 'foo?) p) (app_form c (ref_form 'bar)) a).