background preloader

Clojure

Facebook Twitter

プログラミング言語Clojureのニャンパスでの活用事例. Heroku - Clojure で Slack の Bot を作ろう. 今回は拙作の jubot というフレームワークを使って Clojure で Bot を作り、それを Heroku へデプロイ、Slack と連携させるまでの手順を紹介したいと思います。 Jubot とは Chatbot framework in Clojure. Clojure で Chatbot を作るためのフレームワークです。 いかに私が楽して開発できるかを考えて作っているので、比較的簡単に Bot を実装することができます。 Ver 0.0.1 では Slack との連携、Redis を使ったデータ永続化、タスクのスケジュール実行をサポートしていますが、今回は Slack との連携にフォーカスを絞って説明します。 対象としている環境 Clojure の実行環境があればどこでも Windows は未確認 なお Clojure の開発に必要な JDK, Leiningen のインストールは済んでいるものとして話を進めます。

開発の流れ 基本的な開発の流れは以下の通りです。 テンプレートを作成するハンドラーを作成する動作確認 テンプレートを作る まずは Bot のテンプレートを作りましょう。 $ lein new jubot mybot $ cd mybot ハンドラーを作成する jubot ではユーザーの入力に対して Bot が反応する内容をまとめた処理をハンドラーといいます。 作成したテンプレートにはサンプルのハンドラーが含まれているので、今回はそれを見てみましょう。 Src/mybot/sample/pingpong.clj これは "ping" という入力に対して "pong" と返すハンドラーです。 戻り値として文字列を返せば、それが入力へのレスポンスになります。 また見てわかる通り jubot のハンドラーは単なる関数で、DSLは使いません。 学習コストが低いテストが書きやすい 上記サンプルのテストは test/mybot/sample/pingpong_test.clj にあります。

ハンドラーの命名規則 学習コストが低いといっても全くルールがないわけではありません。 動作確認 では実際にサンプルのハンドラーを動かしてみましょう。 サンプルのように "pong" が返ってきましたか? 修正したソースの反映 Procfile 最後に. Clojure で chatbot 作るライブラリ作った. Liquidz/jubot. Liquidz/cuma. Clj-jwt 0.0.10 - Clojars. Core.typed_annotation_patterns.md. Mikeflynn_ : The first mention of #clojure ... Clojars. Nightcode. Liquidz/cuma. The RedMonk Programming Language Rankings: January 2014. As long as we have been doing our programming language rankings here at RedMonk, dating back to the original publication by Drew Conway and John Myles White, we have been trying to find the correct timing. Should it be monthly? Quarterly? Annually? While the appetite for up to date numbers is strong, the truth is that historically changes from snapshot to snapshot have been minimal. This is in part the justification for the shift from quarterly to bi-annual rankings. This month’s ranking, however, may call that approach into question. Previously, GitHub’s Explore page ranked their top programming languages – theoretically by repository – and we simply leveraged those rankings in our plot.

Besides that notable caveat, there are a few others to reiterate here before we get to the plot and rankings. With that, here is the first quarter plot for 2014. (embiggen the chart by clicking on it) A few observations of larger trends: Eriksvedang/othello. Tokyo.clj #18. Light Tableのプラグインでのnode.jsモジュールの使い方メモ. Liquidz/lt-splash. Light Tableの簡単なプラグインを作ってみた.

Light Table 0.6.0 からオープンソースになり、さらにプラグインに対応したとのことで今、Light Table 熱がすごいですね。 プラグインについての詳細なドキュメントはまだ出てないようですが、次々と新しいプラグインが作られているのを見て自分も負けてられないと思い、 勉強のために既存のプラグインを参考に簡単なプラグインを作ってみました。 Trailing-whitespace† 末尾に空白があった場合にそれを見やすく表示してくれるプラグインです。 元々 Light Table には :lt.objs.editor.file/remove-trailing-whitespace という設定があり保存時に末尾空白を削除してくれますが、例え保存してもファイルを開き直さない限り末尾空白が残ってしまうので、気付かずに行ごとコピーすると末尾空白も含まれてしまいます。 そういったことを避けるために、このプラグインを使うと保存前でも末尾空白の存在を把握できるようになります。 このプラグインを作るにあたって、Light Table は CodeMirror をベースにしているので、CodeMirror のアドオンを移植するのが一番簡単そうと思い、以下のアドオンをベースに選びました。 Edit/trailingspace.jsAdds an option showTrailingSpace which, when enabled, adds the CSS class cm-trailingspace to stretches of whitespace at the end of lines. メインとなる処理はほとんど JS のソースをそのまま ClojureScript に持っていっているだけですが、 設定の有効・無効の切り替えなど Light Table 固有の箇所は以下のプラグインを参考にしました。 Whitespace 空白を可視化するというシンプルなプラグインでコードも短くわかりやすいです。

Declassifier Light Table のサンプルプラグインです。 Claire ファイル検索のプラグインです。 最後に† Light Table Workflow for Interactive Clojure Development. ← Using Ember.js Outlets | Safari’s Clojure Collection → A guest post by Timothy Pratley, who currently works for Tideworks Technology as a Development Manager building Traffic Control software for logistics clients including SSA Marine, CSX, and BNSF. Interactive development is a big win. Being able to evaluate snippets of code without building and running your entire project makes it faster to test code. Being able to modify code and data in a running system allows you to experiment with data and operations immediately. 1.

Start by opening a command window. Cd /mywork lein new interact 2. Launch Light Table. You will see this: 3. Press CTRL-SHIFT-ENTER to evaluate the entire file. Now at the bottom of the file type (+ 1 2) press CTRL-ENTER to evaluate the current form. 3 is displayed in blue near the form, indicating the result. 4. Try calling the existing foo function by typing (foo) on a new line and pressing CTRL-ENTER. Oh no, we forgot to pass in an argument!

(defn bar [] (foo)) (bar) Google Groupes. Joxa. Clj-time/clj-time. Ehrdclj : .@skuro talking about misaki... Liquidz/clj-jwt. Light Table 0.4. 28 Apr 2013 Today, I'm proud to announce the 0.4 release of Light Table - go download it! A bit of the future. With this release our goal was to bring more people into the fold, to increase the number of languages we can eval, and to smooth out some of the core experience. After 0.3, we finally had a chance to move the ball forward some - from live modifying websites directly inside of LT to injecting code into NodeJS and showing matplotlib graphs inline. This is a huge release in virtually every way and I think there's something for everyone, whether you're just starting out programming or you've been writing python since it was released. Next-gen web dev One of the things I originally showed in the Light Table videos was the ability to embed your work directly into Light Table itself.

You can now stick a browser in a tab, navigate to any page you want and start live modifying it. But the most powerful thing to me is the level of eval we now have. Speaking snake: Python support SSssssss. Clojure Cup 2013. Uochan. Liquidz/cuma. Clojureのテンプレートエンジン「cuma」を作ったクマー. Clojureでシンプルなテンプレートエンジンを作りました cuma: Extensible micro template engine for Cl 動機† もともと、misakiなどではclostacheというテンプレートエンジンを使ってました。 これはmustacheのClojure版で、これはこれでとても素晴らしいものなのですが misaki-markdown を開発する上で 以下2つの問題にぶつかりました以下2つの問題にぶつかりました 置き換える文字列中にテンプレートの表記があると正しく置き換えられない機能拡張ができない 前者については送ったpull-requestがマージされたので解消されていますが、後者についてはそもそもmustacheが Logic-less templates を謳っているので 方向性が違うのかと思います。

そこでシンプルなフォーマットを保ちつつ、clojureで機能拡張できるものとしてcumaを作りました。 なぜ「cuma」なのかというと、別に自分がクマ好きでカバンとか携帯にクマのぬいぐるみを付けてるからとかそういうのではなく 'CloUreのteMplAte'からテキトーに文字をピックアップしただけです。 特徴† Clostacheと同じことは同じようにできます。 拡張機能† cumaでは上記フォーマットを保ったまま機能拡張することができます。 Cumaでは実行時に cuma.extension.* という名前空間を検索し、その中のpublicな関数を 拡張機能としてロードし、テンプレート内で使うことができます。 (ns cuma.extension.hello) (defn hello [data s] (str "hello " s)) (render "$(hello x)" {:x "world"});=> hello world パフォーマンス† シンプルなテンプレートなのに動作が遅かったら論外かと思います。

なお計測に使ったコードはgistに貼り付けておきました。 最後に† Tnoda-clojure • うごメモはてなの情報取得 API サンプルコード. Engelberg/instaparse. Micro_sexp_template.clj. プログラマのための言語別コーディング規約まとめ. みなさんはコーディング規約を利用していますか。 個人で開発している時はオレオレルールで良かったのですが、 複数人で開発するようになると共通のルールがあった方がストレス無く開発が出来るようになります。 WEB系の言語のコーディング規約について、調べ物が必要だったので、 まとめたものをブログでもシェア。 Google HTML/CSS Style Guide の推奨ガイドラインまとめ コーディングガイドライン(HTML5)ver1.0 JavaScript JavaScriptのいろいろなコーディングルールをまとめてみた PHPのコーディング規約 PSR-0、PSR-1、PSR-2、PSR-3とは WordPress コーディング基準 Pear Manual :: 標準コーディング規約 Zend Framework PHP 標準コーディング規約 CakePHP コーディング規約 Symfony2 コーディング規約 CodeIgniter PHP コーディングスタイル Ruby Rubyアソシエーション: コーディング規約 コーディング規約をまとめてみた (Ruby編) コーディング規約をまとめてみた (Rails編) Python サイボウズのPython コーディング規約 11 カ条 Python の Coding Style あれこれ Objective-C Objective-Cコーディング規約 Perl サンプルコードによるPerl入門のコーディングルール.

Bbatsov/clojure-style-guide · GitHub. Liquidz/misaki at 0.2.6-beta. Clojure(ある意味)基礎文法最速マスター - athosの日記. (このエントリはLisp Advent Calendar 2012 1日目の記事です。) はじめに 2年ほど前に、「◯◯言語基礎文法最速マスター」という、それぞれの言語の基本的な文法を説明したブログ記事を書くのが大流行した時期がありました。 その流行り具合は、まとめ記事にまとめられた記事の数を見てもうかがい知ることができると思います(たとえば、こことか→プログラミング基礎文法最速マスターまとめ - ネットサービス研究室)。 それで、これだけたくさんの言語がカバーされてれば当然Clojureもあるだろうと思ってググってみましたが、意外にも2年経った今も「Clojure基礎文法最速マスター」はないみたいです。 で、僕は入門記事みたいなのは書くのが苦手なのでやらないんですが、「Clojureの基礎文法とは何ぞや」ということを改めて考えてみました。 それでは、順にClojureの特殊形式を見ていきましょう*1。 Clojureの特殊形式 var オブジェクトとしてVarを参照するときの特殊形式。

User=> (ns foo)nil foo=> (defn- f [x] (* x x)) #'foo/f foo=> (in-ns 'user) #<Namespace user> user=> (f 4) CompilerException java.lang.RuntimeException: Unable to resolve symbol: f in this context, compiling:(NO_SOURCE_PATH:9) user=> ((var foo/f) 4) 16 user=> (#'foo/f 4) 16 user=> あとは、Varにつけられたメタデータを参照したい場合にも使えます。 User=> (meta #'cons){:ns #<Namespace clojure.core>, :name cons, :arglists ([x seq]), :added "1.0", :static true, :doc "Returns a new seq where x is the first element and seq is\n the rest. ", :line 22, :file "clojure/core.clj"} user=> new . let* fn* Meet the new Light Table. 05 Nov 2012 Meet the new Light Table We have to start with a picture. Or hey, just go download it and see for yourself. This is the new Light Table - rewritten from the ground up after having learned a ton about what it's going to take to make a truly extensible and connected environment.

There are a lot of interesting ideas under the hood that make up the core of this new implementation, but the important part is that it is a solid foundation for us to continue forward on. The new code is not only smaller, but far more robust, and allows us to iterate incredibly quickly. But the changes aren't just all under the hood. Yeah, yeah, what's new? Well, let's see it in action. A real app First and foremost, Light Table is now a real app, not some weird concotion of a clojure server and a browser. General editing The 0.2.0 release has more of the general editing features you'd expect in a programming environment. Eval from any file Connect to multiple projects A new, beautiful brand The plan. Static - Static Site Generator. Resources from Jason Rudolph's "ClojureScript Experience Report"

Light Table reaches 0.1.0. 17 Aug 2012 Light Table reaches 0.1.0 The Light Table Playground is getting a huge update today that we're really excited to show you. New to Light Table? It's a new kind of reactive IDE, check out the original post to learn more. A new launcher While the shell scripts got us this far, it's time to bid them farewell and move to a much more robust and useable jar-based launcher. The experience of getting the Playground is now to just download the jar and double click it.

A new mode Previously, the playground included only the Instarepl - a live code evaluation editor that showed you how values were flowing through - but in the latest release it gets a new mode: the "Table". Once connected to a project, you can explore the namespaces in your project with the namespace browser. One of the things we're really excited about testing out is the notion of a "Code Document. " A new double click experience for Clojure Real work and experiments A couple known problems: Moving forward. 10 Tech Skills That Will Instantly Net You $100,000+ Salary. Photo by liquidz_uo.

Squid's Blog. Clojure. 外部S式リード時のエラー行取得. Misakiではプロジェクト外の*.cljファイルをリードしてHTMLに変換しているのですが、 そのcljファイルにエラーがあったとしても今まではmisaki内の評価関数内のエラーとして 例外が発生してしまって、具体的なエラー箇所がぱっとわかる状態ではありませんでした。 解決策† これを解決するためにclojure.core/readで使っているjava.io.PushbackReaderを プロキシする形で行数をカウントするようにしてみました。 (defn create-pushback-reader-with-line [in] (let [line-num (atom 1)] (proxy [PushbackReader IDeref] [in] (read [] (let [c (proxy-super read)] (if (and (not= -1 c) (= \newline (char c))) (swap! Line-num inc)) c)) (deref [] @line-num)))) readをオーバーライドして改行があった場合にline-numをインクリメントしているだけです。 Clojure.lang.IDerefを継承しているのはderefでカウントした行数を取得するためです。 (require '[clojure.java.io :as io]) (let [r (io/reader "file-path.clj") pbr (create-pushback-reader-with-line r)] ; 通常のread (println (.read pbr)) ; 行数を取得 (println @pbr)) これで各S式がファイルのどの行数に書かれているかをリード時に把握できようになったので あとは以下のようにclojure.core/readのエラー時に行番号を利用するだけです。

上記の例は実際にはEOFまでループしなければ意味がないのですが、 そこまで書くと肝心の部分が見づらくなるので省略しました。 なおあくまでもリード時の処理だけなので、評価時のエラー(例えば未定義変数へのアクセス)は 評価関数内のエラーとして扱われます。 また私が他の方法を知らないのでこういった方法で対応しましたが、 もし他にスマートな方法があれば是非教えてください! ClojureProgrammingお菓子会(仮) ゆるーくのんびりがモットーの読書会です。 オライリーから出版されているClojureProgrammingをみんなで読みながらお菓子食べましょう。 英語でなかなかヤル気が出ないし、出ても続かないので、一緒に読んでくれる方募集します。 とりあえず、まだ持ってない方もいらっしゃると思うので、メインは無料サンプル部分を読みましょう。 O’Reilly Clojure Programming もし、既に本を持っていてやる気のある方は、発表歓迎! 無料サンプル以外の部分について、まとめてプレゼンしていただけるかたは @Kuchitama までご連絡ください。 詳細については、順次更新させていただきます。 内容 引き続き発表者募集中 ゆるっとなんとなくでOKです。 5~20分くらいまでで、無理なく発表できる内容、時間で大丈夫ですb 会場について 会場のニッセイ京都駅前ビルは休日は入り口が閉じていますので、@kuchitamaが開閉します。 会場の環境 ディスプレイはこちらで用意します。 ネットワークは、@kuchitamaが8台まで接続できるwimaxを用意しますが、個人でお持ちの方は、ご持参頂けると幸いです。 集合場所と時間 会場の都合上、入場時間を設定させていただきます。 Clojureでブログ生成: misakiのベータ版公開.

実際の公開からちょっと間空いてしまいましたが、 misakiのベータ版を公開しました。 Misakiとは? † rubyのJekyllを参考にClojureで作った静的サイトジェネレータです。 当ブログもmisakiで生成していて、 misaki自体のドキュメントもmisakiで管理・生成しています。 何が新しいの? † ベータ版で追加した主な機能は以下の通りです。 Clojurescriptへの対応出力のカスタマイズビルトイン関数の拡充スマホ対応 Clojurescript対応† 設定ファイルに定義を追加することでClojurescriptをビルドすることができるようになりました。 ;; clojurescript compile options ;; src-dir base is `:template-dir` ;; output-dir base is `:public-dir` :cljs {:src-dir "cljs" :output-to "js/hello.js" :optimizations :whitespace :pretty-print true} 上記の定義を _config.clj に書く(デフォルトでコメントアウトされています)ことで テンプレートディレクトリ(:template-dir)内のcljsディレクトリにあるcljsファイルを 出力先ディレクトリ(:public-dir)のjs/hello.jsとしてビルドします。 出力のカスタマイズ† Alpha版で指定できたポストファイル名の正規表現と出力ファイル名は ブログ生成に重点を置いていたため日付が付くことが前提でカスタマイズとしては微妙な機能でした。

ドキュメントの:post-filename-regexpはデフォルトのままですが、 実際のポストのファイル名は"01-getting-started.html.clj"となっており、日付に縛られていないことがわかります。 ビルトイン関数の拡充† Alpha版ではhiccupを使ったS式からHTMLへのコンパイラという意味合いが強かったのですが、 Beta版ではテンプレートを生成するためのビルトイン関数を(ある程度)充実させました。 スマホ対応† あくまで共通機能を使っている場合のみなので、 どんな使い方をしてもスマホ対応できるわけではないのでご注意ください。 Light Table Playground Levels Up. 09 Jul 2012 I'm happy to announce the release of v0.0.7 of the Light Table Playground. This version is a serious upgrade to the Instarepl that brings the ability to manually evaluate things and work in your own projects.

Here's a breakdown of what's new. A little guide The first thing you're greeted with when you open 0.0.7 is what we're calling the shade. The shade shows you new things that you can do and acts as a sort of interactive change log. Manual Mode You now have the ability to enter manual mode in the Instarepl, by simply clicking the live button in the top right, or by pressing Cmd/Ctrl-L. Once in manual mode, code is no longer evaluated as you type, but instead when you trigger evaluation of the whole editor with Cmd/Ctrl-Enter or a single form using Shift-Enter. Sidebar The sidebar is currently just a simple menu, but will ultimately be the source of a lot of interaction with Light Table's command set. Currently it only has two verbs: connect and set. Lein-light Misc. Core.logic. It's playtime. 24 Jun 2012 I'm happy to announce the official release of the Light Table Playground!

You can find instructions for getting it here: What is the playground? The playground is a chance for you to follow along as we test out new things for Light Table. In return, it helps us collect metrics on how people are using our experiments as well as gives us an opportunity to see how certain concepts fare in the real world. All in all, it keeps us connected to you guys and you guys connected to us.

Currently, the playground includes what we call the "instarepl" for Clojure. Wait, what's Kodowa? Kodowa is the official entity behind Light Table. The plan moving forward The playground is a very stripped down version of Light Table, but it helps us prove out the platform necessary to support the vision we've laid out. Core — Reducers - A Library and Model for Collection Processing. ChottoJob. Light Table by Chris Granger. Clojure1.4のReader Literalsで遊んでみた.

Clojure 1.4.0, clj-time, congomongo. Light Table's numbers. Light Table - a new IDE concept. Mocking out in Clojure with with-redefs-fn (no Midje this time) | Japila :: verba docent, exempla trahunt. Where is Lisping headed? ClojureでJekyllライクなブログジェネレータ「misaki」を作ったった. 全部Clojureのターン(noir+noir-cljs) Parallel SSH and system monitoring in Clojure. Leiningen 2.0.0-preview - Google Groupes. Clojure Libraries.

4clojure – Welcome!