• This repository has been archived on 09/Nov/2017
  • Stars
    star
    98
  • Rank 345,882 (Top 7 %)
  • Language
    Clojure
  • Created about 12 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

whole-program transformations in clojure

Sleight allows pervasive transforms to Clojure code, akin to wrapping all your code and the code in the libraries you depend on in the same macro.

what is this good for?

Possible uses include:

  • language extensions
  • pervasive inversion-of-control transforms
  • automatic instrumentation
  • test coverage metrics
  • anything else you can dream up

is this a good idea?

Maybe!

how do I use it?

Sleight can be used via the lein-sleight plugin. To use in all projects, add [lein-sleight "0.2.2"] to the :plugins vector of your :user profile in ~/.lein/profiles.clj.

To use for a specific project, add [lein-sleight "0.2.2"] to the :plugins vector in project.clj.


Once this is done, define a transform in your project or one of its dependencies.

(def reverse-vectors
  {:pre (fn [] (println "Get ready for some confusion..."))
   :transform (fn [x] (riddley.walk/walk-exprs vector? reverse x))
   :post (fn [] (println "That probably didn't go very well"))})

A transform is defined as a map containing one or more of the keys :pre, :transform, and :post. The :pre callback is invoked before the reader is hijacked to perform the transformation, the :transform function is passed each form as it's read it, and returns a modified form. The :post callback is invoked as the process is closed.

To perform safe code transformations, use Riddley.

Then, in your project.clj, add something like this:

(project your-project "1.0.0"
  :sleight {:default {:transforms [a.namespace/reverse-vectors]}
            :partial {:transforms [a.namespace/reverse-vectors]
                      :namespaces ["another.namespace*"]}})

The :transforms key maps onto a list of transforms, which are applied left to right. The :namespaces key maps onto a list of namespace filters, which confines the transformation to namespaces which match one of the filters.

lein sleight is not a standalone task, it's meant to modify other tasks. For instance, if we want to apply our transform to code while testing, we'd run:

lein sleight test

Since we haven't given a selector before the test task, the :default transform is selected. To specify the :partial transform, we'd run:

lein sleight :partial test

license

Copyright (C) 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

riddley

code-walking without caveats
Clojure
197
star
7

clj-tuple

efficient small collections for clojure
Java
179
star
8

narrator

expressive, composable stream analysis
Clojure
152
star
9

proteus

local. mutable. variables.
Clojure
113
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