我最近对Chris Granger和他的Light Table的工作留下了深刻的印象.这个问题不是关于光桌,而是关于他在博客文章"作为一种价值的IDE"中描述的"BOT"架构的更多信息:http: //www.chris-granger.com/2013/01/24/所述-IDE作为数据/
现在,我对clojure很新,但想更好地探索这种编程方式:行为,对象,标记:
(behavior* :read-only
:triggers #{:init}
:reaction (fn [this]
(set-options this {:readOnly "nocursor"})))
(object* :notifier
:triggers [:notifo.click :notifo.timeout]
:behaviors [:remove-on-timeout :on-click-rem!]
:init (fn [this]
[:ul#notifos
(map-bound (partial notifo this) notifos)]))
(object/tag-behaviors :editor.markdown [:eval-on-change :set-wrap])
Run Code Online (Sandbox Code Playgroud)
我在哪里可以找到使用该样式的clojure代码和那些组合原则?
所以我有一个函数列表和一个数据列表:
[fn1 fn2 fn3] [item1 item2 item3]
Run Code Online (Sandbox Code Playgroud)
如何将每个函数应用于其相应的数据项:
[(fn1 item1) (fn2 item2) (fn3 item3)]
Run Code Online (Sandbox Code Playgroud)
例:
[str #(* 2 %) (partial inc)] [3 5 8]
=> ["3" 10 9]
Run Code Online (Sandbox Code Playgroud) 我刚开始使用Om(基于reactjs的ClojureScript库).我想根据用户输入过滤列表.以下工作,但解决方案似乎是复杂的.还有更好的吗?
(ns om-tut.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[clojure.string :as string]))
(enable-console-print!)
(def app-state (atom {:list ["Lion" "Zebra" "Buffalo" "Antelope"]}))
(defn handle-change [e owner {:keys [text]}]
(om/set-state! owner :data (vec (filter (fn [x] (> (.indexOf x(.. e -target -value)) -1)) (@app_state :list))))
(om/set-state! owner :text (.. e -target -value)))
(defn list-view [app owner]
(reify
om/IInitState
(init-state [_]
{:text nil
:data (:list app)
})
om/IRenderState
(render-state [this state]
(dom/div nil
(apply …Run Code Online (Sandbox Code Playgroud) 给定分离的哈希映射的向量的集合
我该怎么做:
[[{:a 1} {:b 2} {:c 3}] [{:a 4} {:b 5} {:c 6}] [{:a 7} {:b 8} {:c 9}]]
Run Code Online (Sandbox Code Playgroud)
至:
[[{:a 1 :b 2 :c 3}] [{:a 4 :b 5 :c 6}] [{:a 7 :b 8 :c 9}]]
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答!
我想使用Light Table突出显示Hoplon(http://hoplon.io/)代码.
我有一个分类的clojure网络应用程序,我想在Heroku上托管.该域名在Godaddy注册.
拥有多个子域的最有效和最有效的方法是什么:
用户,所有逻辑,应该跨子域共享,所以我希望只有一个代码库.
将子域重定向到第一级文件夹很容易,如下所示:
paris.classapp.com- >classapp.com/paris/
但我希望用户在浏览网站时继续看到子域名,如下所示:
paris.classapp.com/cars/blue-car-to-sell
与此相反:classapp.com/paris/cars/blue-car-to-sell
我该怎么办?
当访问者提交表单时,我想联系他们输入他的IP地址.
(POST "/form" {params :params} (assoc params :ip-address the-ip)
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
想到这样做:
(POST "/form" {params :params
client-ip :remote-addr}
(->> params keywordize-keys (merge {:ip-address client-ip}) str))
Run Code Online (Sandbox Code Playgroud)
但这会回来 {... :ip-address "0:0:0:0:0:0:0:1"}
我刚刚尝试添加此包装器(-> routes (wrap-ssl-redirect))以将 http 自动重定向到 https,但是当我部署到 heroku 时,https://浏览器中没有显示绿色,网站也没有加载。
不是默认的 heroku port 443,它也应该是wrap-ssl-redirect函数的默认值吗?
怎么了?
谢谢!
编辑:
我的代码:
(defn prod-app [routes]
(-> routes
(wrap-keyword-params)
(wrap-params)
(wrap-ssl-redirect)))
(defn -main []
(let [port (Integer/parseInt (get (System/getenv) "PORT" "5000"))]
(jetty/run-jetty (prod-app domain-specific-routes)
{:port port :join? false})))
Run Code Online (Sandbox Code Playgroud)
编辑2:
我刚刚找到了可以解决我的问题的线程:Clojure / Noir: Force HTTPS, 如果请求是 http:// 到 https://,则重定向
想出了这个require-https处理程序 fn:
(defn https-url [request-url]
(str "https://"
(:server-name request-url)
":"
(:server-port request-url)
(:uri request-url)))
(defn require-https
[handler]
(fn [request] …Run Code Online (Sandbox Code Playgroud) 假设我有一个需要两个参数的函数,并且参数的顺序会影响结果.
是否可以将第一个参数传递给partial或comp函数而另一个参数除以它,如下所示:
(defn bar [arg1 arg2] (- arg1 arg2))
(def baz (partial (bar arg1)))
(def qux (comp str (bar arg1)))
(baz arg2)
(qux arg2)
Run Code Online (Sandbox Code Playgroud)
如果我想将arg2传递给函数,我可以这样做吗?
(def baz2 (partial (bar _ arg2)))
(def qux2 (comp str (bar _ arg2)))
(baz arg1)
(qux arg1)
Run Code Online (Sandbox Code Playgroud) 我有这个功能:
(defn list-data [alist filter-text]
(filter (fn [x] (if (nil? filter-text) true
(> (.indexOf x filter-text) -1))) alist))
(list-data ["Lion" "Zebra" "Buffalo" "Antelope"] "a")
;=> ("Zebra" "Buffalo")
Run Code Online (Sandbox Code Playgroud)
是否有更惯用的方式编写此函数并尊重我不想要区分大小写的过滤器这一事实,这意味着我希望(list-data ["Lion" "Zebra" "Buffalo" "Antelope"] "a")返回以下内容:
;=> ("Zebra" "Buffalo" "Antelope")
Run Code Online (Sandbox Code Playgroud)
谢谢!
(这需要在.cljs文件中工作)
clojure ×10
ring ×3
composition ×1
heroku ×1
hoplon ×1
https ×1
lighttable ×1
om ×1
reactjs ×1
subdomain ×1