(defprofile lagénorhynque
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dev> (require '[libpython-clj.python :as py]) | |
nil | |
dev> (py/initialize! :python-executable venv-python | |
:library-path dylib-path) | |
... | |
dev> (require '[libpython-clj.require :refer [require-python]]) | |
nil | |
dev> (require-python '[numpy :as np] | |
'[numpy.random :as np.rand] | |
'[pandas :as pd]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dev> (if-let [coll (seq [1 2 3])] | |
(println coll) | |
(println "EMPTY")) | |
(1 2 3) | |
nil | |
dev> (if-let [coll (seq [])] | |
(println coll) | |
(println "EMPTY")) | |
EMPTY | |
nil |
(defprofile lagénorhynque
:id @lagenorhynque
:reading "/laʒenɔʁɛ̃k/"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* (defparameter xs '(1 2 3)) | |
XS | |
* xs | |
(1 2 3) | |
* (nreverse xs) | |
(3 2 1) | |
* xs | |
(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ clj | |
Clojure 1.10.1 | |
user=> (defn plus [& args] | |
(apply + args)) | |
#'user/plus | |
user=> (plus 1 2 3) | |
6 | |
user=> (apply plus [1 2 3]) | |
6 |
(defprofile lagénorhynque
:id @lagenorhynque

新たなプログラミング言語に入門したら、早く実用的なアプリケーションを作ってみたくなるものです(ちなみに私 lagénorhynque🐬 は最近、Elixirに入門しました)。
コミュニティの発展とともにClojureの応用領域もますます拡大していますが、定番は何よりWeb開発ということで本記事では素早く最小構成的にREST APIを開発する方法を紹介します。
DuctやLuminusなどWebアプリ開発をスムーズにするための(マイクロ)フレームワークが有名なものだけでもいくつか存在しますが、今回はHTTPサーバ抽象と基本的なユーティリティを提供するRingとルーティング機能を提供するbidiによるミニマルな実装を考えます。
サンプルコードはPythonライブラリFlask-RESTfulのドキュメントQuickstartの例を参考にし、敢えて名前空間を分割せず1ファイルにまとめる構成にしています。
- Leiningen版: [minimal-api-lein](https://github.com/lagenorhynque/clojure-rest-api-quickstart/tree/maste
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (defn counter [init] | |
(let [c (atom init)] | |
#(swap! c + %))) | |
#'user/counter | |
user> (def c1 (counter 0)) | |
#'user/c1 | |
user> (def c2 (counter 0)) | |
#'user/c2 | |
user> (c1 2) | |
2 |