Uploaded image for project: 'core.logic'
  1. LOGIC-187

*locals* is unbound in some calls to `p->term`

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:

      I am using Clojure 1.9.0, core.logic 0.8.11, on macOS 10.14.

      Description

      Some pattern-matching expressions that should work fail, because the dynamic variable `locals` is not bound. For example:

      (matche
      [x]
      (['(~a)]))

      gives an error during macroexpansion, that `contains?` cannot be applied to an unbound variable:

      CompilerException java.lang.IllegalArgumentException: contains? not supported on type: clojure.lang.Var$Unbound

      (The referenced call to contains? is in lvar-sym?, where we check whether a variable that appears within a pattern is already a local variable.)

      I believe this is what is happening:

      1. At two places in `p->term`, we call `map` to apply p->term recursively to subpatterns: `(map #(p->term % vars quoted) p)`, for example.
      2. `map` returns a LazySeq.
      3. By the time the elements of the LazySeq are actually forced (this happens during macro expansion), the dynamic locals variable is no longer bound.

      One solution might be to wrap a `(doall ...)` around the two calls to `map` mentioned above (lines 1523 and 1529 of logic.clj).

        Attachments

          Activity

            People

            • Assignee:
              dnolen David Nolen
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: