Skip to content

Commit

Permalink
mark 0.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ztellman committed Oct 24, 2014
1 parent a509405 commit ad57fe8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
@@ -1,3 +1,5 @@
![](docs/riddley.jpg)

Walker is my name
and I am the same.
Riddley Walker.
Expand All @@ -23,7 +25,7 @@ This means that transforms that we intend to apply to expressions may have unint
[![Build Status](https://travis-ci.org/ztellman/riddley.png?branch=master)](https://travis-ci.org/ztellman/riddley)

```clj
[riddley "0.1.7"]
[riddley "0.1.8"]
```

Riddley provides a correct `riddley.walk/macroexpand-all`, which preserves the binding information in `&env` and expands inlined functions, and `riddley.walk/walk-exprs`, which is a general mechanism for code walking and transformation.
Expand Down
Binary file added docs/riddley.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 17 additions & 11 deletions src/riddley/walk.clj
Expand Up @@ -23,14 +23,14 @@
(if (or
(and special-form? (special-form? frst))
(contains? (cmp/locals) frst))

;; might look like a macro, but for our purposes it isn't
x

(let [x' (macroexpand-1 x)]
(if-not (identical? x x')
(macroexpand x' special-form?)

;; if we can't macroexpand any further, check if it's an inlined function
(if-let [inline-fn (and (seq? x')
(symbol? (first x'))
Expand All @@ -44,7 +44,7 @@
(macroexpand
;; unfortunately, static function calls can look a lot like what we just
;; expanded, so prevent infinite expansion
(if (= '. (first x''))
(if (= '. (first x''))
(with-meta
(concat (butlast x'')
[(if (instance? clojure.lang.IObj (last x''))
Expand All @@ -61,6 +61,11 @@

;;;

(defn- do-handler [f [_ & body]]
(list* 'do
(doall
(map f body))))

(defn- fn-handler [f x]
(let [prelude (take-while (complement sequential?) x)
remainder (drop (count prelude) x)
Expand All @@ -81,7 +86,7 @@
(cmp/register-local nm
(list* 'fn* nm
(map #(take 1 %) remainder))))

(concat
prelude
(if (seq? (first remainder))
Expand Down Expand Up @@ -203,12 +208,13 @@

(and (walkable? x) (= 'quote (first x)))
(list* 'quote (walk-exprs predicate handler (constantly true) (rest x)))

(predicate x)
(handler x)

(walkable? x)
((condp = (first x)
'do do-handler
'def def-handler
'fn* fn-handler
'let* let-handler
Expand All @@ -221,28 +227,28 @@
'. dot-handler
#(doall (map %1 %2)))
walk-exprs' x)

(instance? java.util.Map$Entry x)
(clojure.lang.MapEntry.
(walk-exprs' (key x))
(walk-exprs' (val x)))

(vector? x)
(vec (map walk-exprs' x))

(instance? clojure.lang.IRecord x)
x

(map? x)
(into {} (map walk-exprs' x))

(set? x)
(set (map walk-exprs' x))

;; special case to handle clojure.test
(and (symbol? x) (-> x meta :test))
(vary-meta x update-in [:test] walk-exprs')

:else
x)]
(if (instance? clojure.lang.IObj x')
Expand Down

0 comments on commit ad57fe8

Please sign in to comment.