rm-hull / infix

A Clojure library for expressing LISP expressions as infix rather than prefix notation
https://www.destructuring-bind.org/infix/
MIT License
106 stars 11 forks source link

Unable to load infix 0.3.2 #30

Closed teodorlu closed 6 years ago

teodorlu commented 6 years ago

Hello!

Using a minimal Leiningen project depending on rm-hull/infix "0.3.2", I start a lein repl and

user=> (require '[infix.core :as i])
;; ... I get the error:
CompilerException java.lang.RuntimeException: Unable to resolve var: v in this context, compiling:(infix/core.clj:145:35) 

Should this happen? Leftovers from a REPL session, perhaps? Here's the relevant lines from my local jar included below.

Regards, Teodor

(defn rewrite
  "Recursively rewrites the infix-expr as a prefix expression, according to
   the operator precedence rules"
  [infix-expr]
  (cond
    (not (seq? infix-expr))
    (resolve-alias infix-expr)

    (and (seq? (first infix-expr)) (= (count infix-expr) 1))
    (rewrite (first infix-expr))

    (empty? (rest infix-expr))
    (first infix-expr)

    :else
    (let [infix-expr (map resolve-alias infix-expr)]
      (loop [ops operator-precedence]
        (if-let [op (first ops)]
          (let [idx (.lastIndexOf ^java.util.List infix-expr op)]
            (if (pos? idx)
              (let [[expr1 [op & expr2]] (split-at idx infix-expr)]
                (list op (rewrite expr1) (rewrite expr2)))
              (recur (next ops))))

          (if (empty-arglist? infix-expr)
            (list (rewrite (first infix-expr)))
            (list (rewrite (first infix-expr)) (rewrite (next infix-expr)))))))))

(def base-env
  (merge (->>
    @operator-alias
    (map (fn [[k v]] [(keyword k) (var v)])) ;; This is line 145
    (into {}))

   ; Basic ops
   {:== ==
    := =
    :!= not=
    :+ +
    :- -
    :* *
    :/ /
    :% mod}
         )
  )

(println base-env)

(var )

(rewrite '(1 + 3))
rm-hull commented 6 years ago

Sounds like when I cut a release I didnt rebuild properly ... will push out a 0.3.3 fix shortly - apologies

teodorlu commented 6 years ago

Sounds good!

rm-hull commented 6 years ago

0.3.3 deployed onto clojars - let me know if this works for you please @teodorlu

teodorlu commented 6 years ago

All seems to be good with 0.3.3. Thanks for the quick fix!

  (do
    (require '[infix.macros :as m]
             '[infix.core :as c])
    (c/rewrite '(1 + 2 * (3 + 4))))
  ;; => (+ 1 (* 2 (+ 3 4)))