Clojure's :require and Instaparse

北城余情 提交于 2019-12-01 20:21:14

here is a working sample project:

project.clj:

(defproject parse "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [instaparse "1.1.0"]])

you don't need the lines for contrib, and string is built into clojure now.

src/parse/core.clj:

(ns parse.core
  (:require [instaparse.core :as insta]
            [clojure.string :as str]))
(def as-and-bs
  (insta/parser
   "S = AB*
     AB = A B
     A = 'a'+
     B = 'b'+"))

repl:

#<Namespace parse.core>
parse.core>  (as-and-bs "aaaaabbbaaaabb")
[:S [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]] [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]
parse.core> (str/join "," ["a" "b" "c"])                                                                                                                                  
"a,b,c" 

My general Liningen strangeness resolution checklist:

  • run lein deps and restart nrepl/emacs
  • lein clean and restart nrepl/emacs
  • remove the local libs dir (lein v1.x)
  • remove my local maven repository and run lein deps

I've found out what was wrong. I was creating project with leiningen but develop source with Clojure-box or Clooj. I was also trying to compile my source with that tools and it was mistake. When you run such IDE it loads that's own classpath and that is why it could not find library I'd like to use. Now I compile my src with

lein compile

and run it in

lein repl

and everything is just working fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!