簡體   English   中英

使用Leinengen和Clojure在REPL中嘗試新庫的最快方法

[英]Fastest way to try out a new library in a REPL using Leinengen with Clojure

新的clojure開發人員嘗試在REPL中嘗試使用HTTP套件clojure庫

我在leinengen創建了一個新項目, lein new app kit-expt

然后,我修改了project.clj中的:dependencies塊以包含[http-kit "2.2.0"]

然后,我運行lein deps ,然后運行lein repl

在REPL中,我嘗試運行(:require [org.httpkit.client :as http])

但是,當我運行它時,我得到了錯誤

CompilerException java.lang.ClassNotFoundException: org.httpkit.client, compiling:(/private/var/folders/cs/b0kcg6fx0335crbvn6xtgq7xl5c29j/T/form-init7575648818353088270.clj:1:1) 

我究竟做錯了什么?

您使用的:require格式無效,該關鍵字僅適用於ns (命名空間)格式。 嘗試刪除:然后使用(require ... ,這是REPL中常用的。請在此處查看更多require示例。

您引用的HTTP客戶端文檔假定您使用ns在源文件中。

您的環境中似乎有問題。 如果我運行它(Ubuntu 16.04),它將很好地工作:

(require '[org.httpkit.client :as http])
(pr-str (clojure.core/deref (http/get "http://google.com")))) 

   => "{:opts {:method :get, :url \"http://www.google.com/\", :query-params nil, :form-params nil, :trace-re".....

更新

正如Micah指出的那樣,在REPL中,您需要以上形式的require 請注意,它沒有前導冒號,並且在左方括號之前確實有一個單引號。 還必須在括號內,而不是方括號。

ns形式(我更喜歡)中,一切都有相反的約定:

(ns tst.clj.core
  (:use clj.core clojure.test tupelo.test)
  (:require
    [tupelo.core :as t]
    [org.httpkit.client :as http]  ))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM