Suppose you have a lib that causes some errors during loading, like the following:
(ns broken-lib)
(} ; this line will cause a reader error
And then, if you require
the lib, it would be added into loaded-libs
in spite of the reader error,
(require '[clojure.java.io :as io] | |
'[clojure.string :as s]) | |
(defn bench [filename f] | |
(with-open [r (io/reader filename)] | |
(->> (line-seq r) | |
(map f) | |
(group-by first)))) | |
(defn f1 [line] |
(ns six-length.core | |
(:require [clojure.core.reducers :as r] | |
[clojure.string :as s]) | |
(:import [java.security MessageDigest] | |
[javax.xml.bind DatatypeConverter])) | |
(set! *warn-on-reflection* true) | |
(def hexdigest | |
(let [digester (MessageDigest/getInstance "MD5")] |
[:add z x y] | |
[:sub z x y] | |
[:mul z x y] | |
[:div z x y] | |
[:rem z x y] | |
[:eq x y] | |
[:lt x y] | |
[:gt x y] | |
[:neg] | |
[:push z x] |
Suppose you have a lib that causes some errors during loading, like the following:
(ns broken-lib)
(} ; this line will cause a reader error
And then, if you require
the lib, it would be added into loaded-libs
in spite of the reader error,
(defrecord Path [path] | |
clojure.lang.IFn | |
(invoke [this n] | |
(clojure.string/replace path ":id" (str n)))) | |
(defmethod print-method Path [o ^java.io.Writer w] | |
(.write w (str "#path\"" (:path o) "\""))) | |
(set! *data-readers* (assoc *data-readers* 'path ->Path)) |
(ns bowling-game) | |
(defn- apply-to-nonnil [op & args] | |
(->> (reverse args) | |
(drop-while nil?) | |
reverse | |
(apply op))) | |
(defn partition-frames [throws] | |
(loop [n 1, [throw & more] throws, ret []] |
シンタックスハイライトは、キーワードを強調表示し、ソースコードの可読性を高めるためのものであり、今や多くのテキストエディタやコードビューアが標準で備える基本的機能である。シンタックスハイライターは、シンタックスハイライトをするモジュールであり、一般的には簡易的な字句解析により実現される。
しかし、多くの動的言語のシンタックスハイライターは、そのような簡易的な実現手段では不十分である。動的言語では、ひとつのフォームが他のコードの意味に影響を及ぼしうる。そのため、より正確なシンタックスハイライトをするには字句解析や構文解析だけでなく、プログラムの意味を解析する必要がある。
Lisp系言語におけるマクロも、Lispコードのシンタックスハイライトを困難にするひとつの要因である。マクロを使えばユーザが独自に構文を定義できるため、一般のLispコードでは字面上のどのシンボルがローカルな束縛を表しているのかを識別することすら難しい。
本発表では、この課題を解決するために開発中の、マクロを認識するClojure向けのシンタックスハイライターであるgenuine-highlighterと、その基盤ととなっている解析器symbol-analyzerの仕組みについて述べる。また、genuine-highlighterをビルドツールLeiningenから使用できるようにするプラグインについてもデモにより紹介する。
(let [name #(subs (name %) 1)] | |
(name 'foo)) | |
(letfn [(name [sym] (subs (name sym) 1))] | |
(name 'foo)) |
(ns user | |
(:refer-clojure :exclude [send]) | |
(:require [clojure.tools.namespace.repl :refer [refresh refresh-all]] | |
[clojure.repl :refer :all] | |
[clojure.pprint :refer [pp pprint]] | |
[clojure.core.async :as a] | |
[clojure.java.shell :refer [sh]])) | |
(def to-listeners (a/chan)) | |
(def pub (a/pub to-listeners :type)) |
Title | Conference | License |
---|---|---|
Transducers | Strange Loop 2014 | CC BY |
Implementation details of core.async Channels | EuroClojure | CC BY-NC |
Design, Composition and Performance | QCon San Francisco 2013 | InfoQ *1 |
Clojure core.async Channels | Strange Loop 2013 | InfoQ *1 |
The Language of the System | Clojure/conj 2012 | standard YouTube license *2 |
The Value of Values | JaxConf 2012 | standard YouTube license *2 |
Reducers | QCon NY 2012 | InfoQ *1 |
Simple Made Easy |