• Stars
    star
    193
  • Rank 194,252 (Top 4 %)
  • Language
    Clojure
  • Created over 10 years ago
  • Updated over 1 year 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
708
star
2

automat

better automata through combinators
Clojure
586
star
3

rhizome

simple graph and tree visualization
Clojure
446
star
4

penumbra

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

virgil

your own personal JVM psychopomp
Clojure
274
star
6

vertigo

heterogeneous structs for clojure
Clojure
208
star
7

clj-tuple

efficient small collections for clojure
Java
179
star
8

narrator

expressive, composable stream analysis
Clojure
153
star
9

proteus

local. mutable. variables.
Clojure
111
star
10

sleight

whole-program transformations in clojure
Clojure
98
star
11

calx

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

collection-check

fuzz testing for alternate clojure data structures
Clojure
64
star
13

pushkin

shall we play a game?
Clojure
59
star
14

immutable-bitset

space-efficient immutable integer sets
Clojure
51
star
15

immutable-int-map

a map optimized for integer keys
Clojure
40
star
16

aloha

a simple, friendly webserver
Clojure
36
star
17

cambrian-collections

a veritable explosion of data structures
Clojure
29
star
18

cantor

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

clj-radix

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

lein-jammin

a window into your stuck process
Clojure
18
star
21

everything-will-flow

necessary code for my upcoming clojure/west 2015 talk
Clojure
17
star
22

duel

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

bizarro-collections

you got your clojure semantics in my mutable hash-map
Java
7
star
24

ergo

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

scrawl

the graphical equivalent of the fibonacci sequence
Clojure
4
star
26

java9-failure

Clojure
1
star
27

aleph.io

static website for aleph
CSS
1
star