• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    Clojure
  • Created about 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

code-walking without caveats
Walker is my name
and I am the same.
Riddley Walker.
Walking my riddels
where ever theyve took me
and walking them now
on this paper the same.

from Riddley Walker by Russell Hoban


Code may be data, but only some of that data is executable. If we want to perform a pervasive code transformation, using something like clojure.walk presents a few problems:

  • binding forms are treated the same as actual expressions
  • clojure.walk/macroexpand-all will pass in a nil &env to all macros
  • macroexpansion doesn't expand inlined functions

This means that transforms that we intend to apply to expressions may have unintended consequences on a fn, let, or case form. It also means that any macro which relies on &env will not compose with our transformation. Finally, if inlined functions aren't expanded, certain transformations will break.

usage

Build Status

[riddley "0.2.0"]

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.

walk-exprs takes two arguments, a predicate for whether it should transform the sub-form, and a handler for doing the transformation.

riddley.walk> (walk-exprs number? inc '(let [n 1] (+ n 1)))
(let* [n 2] (. clojure.lang.Numbers (add n 2)))

Notice that walk-exprs implicitly macroexpands the form, including the inline form for +. Unlike clojure.walk, if handler is called, sub-forms will not be walked. The handler function is responsible for recursively calling walk-exprs on the form it's handed.

Access to &env is available via (riddley.compiler/locals) if you need it as part of your transformation.

Full documentation can be found here.

license

Copyright © 2013 Zachary Tellman

Distributed under the MIT License.

More Repositories

1

lamina

not under active development - event-driven workflows for clojure
Clojure
709
star
2

automat

better automata through combinators
Clojure
587
star
3

rhizome

simple graph and tree visualization
Clojure
446
star
4

penumbra

not under active development - idiomatic opengl bindings for clojure
Clojure
354
star
5

vertigo

heterogeneous structs for clojure
Clojure
207
star
6

clj-tuple

efficient small collections for clojure
Java
179
star
7

narrator

expressive, composable stream analysis
Clojure
152
star
8

proteus

local. mutable. variables.
Clojure
113
star
9

sleight

whole-program transformations in clojure
Clojure
98
star
10

calx

not under active development - idiomatic opencl bindings for clojure
Clojure
84
star
11

collection-check

fuzz testing for alternate clojure data structures
Clojure
64
star
12

pushkin

shall we play a game?
Clojure
59
star
13

immutable-bitset

space-efficient immutable integer sets
Clojure
51
star
14

immutable-int-map

a map optimized for integer keys
Clojure
40
star
15

aloha

a simple, friendly webserver
Clojure
36
star
16

cambrian-collections

a veritable explosion of data structures
Clojure
29
star
17

cantor

not under active development - primitive math for clojure
Clojure
26
star
18

clj-radix

a persistent radix tree, for efficient nested maps
Clojure
21
star
19

lein-jammin

a window into your stuck process
Clojure
18
star
20

everything-will-flow

necessary code for my upcoming clojure/west 2015 talk
Clojure
18
star
21

duel

a testing ground for programs that play go
Clojure
10
star
22

bizarro-collections

you got your clojure semantics in my mutable hash-map
Java
8
star
23

ergo

a monte-carlo simulator for computer go
C++
5
star
24

scrawl

the graphical equivalent of the fibonacci sequence
Clojure
4
star
25

java9-failure

Clojure
1
star
26

aleph.io

static website for aleph
CSS
1
star