core.logic

cannot emit lvars from macros

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Approval:
    Ok

Description

if we have a pattern matching macro like, for example, a cond-m that does something like
(cond-m some-value
some-pattern some-code-to-execute-on-match
some-other-pattern ...
another-pattern ...)
it would be nice if the work of preping the patterns could be done at compile time and just emit clojure literals representing the prepared patterns, lvars are currently not emittable in code, so the cost of prepping patterns would be incurred at runtime.

Activity

Hide
Kevin Downey added a comment -

this seems to turn an expression containing lvars into something you can return from a macro

(defn emittable [expr]
(postwalk
(fn [expr]
(cond
(mk/lvar? expr)
`(clojure.core.logic.minikanren.LVar.
~(.name expr)
~(.hash expr)
~(.cs expr))
(symbol? expr)
`(quote ~expr)
(seq? expr)
`(list ~@expr)
:else expr))
expr))

Show
Kevin Downey added a comment - this seems to turn an expression containing lvars into something you can return from a macro (defn emittable [expr] (postwalk (fn [expr] (cond (mk/lvar? expr) `(clojure.core.logic.minikanren.LVar. ~(.name expr) ~(.hash expr) ~(.cs expr)) (symbol? expr) `(quote ~expr) (seq? expr) `(list ~@expr) :else expr)) expr))
Hide
Kevin Downey added a comment -

the problem shows up with lcons as well, a possibly solution would be to have lcons and lvar and whatever else have a protocol IEmittable extended to them, where (emit some-lvar) would for example return `(LVar. ~(.name some-lvar) ~(.hash some-lvar) ~(.cs some-lvar))

Show
Kevin Downey added a comment - the problem shows up with lcons as well, a possibly solution would be to have lcons and lvar and whatever else have a protocol IEmittable extended to them, where (emit some-lvar) would for example return `(LVar. ~(.name some-lvar) ~(.hash some-lvar) ~(.cs some-lvar))
Hide
David Nolen added a comment -

This is currently outside scope.

Show
David Nolen added a comment - This is currently outside scope.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: