This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now that we have riddley, this is maybe ready for primetime
- Loading branch information
Showing
15 changed files
with
130 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: clojure | ||
lein: lein2 | ||
script: lein2 do clean, sleight test :make-odd, test :normal | ||
jdk: | ||
- openjdk7 | ||
- oraclejdk7 | ||
- openjdk6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,69 @@ | ||
Sleight allows a transform function to be applied to all forms before they're read in by Clojure's compiler. This is a work in progress, but it will enable | ||
![](docs/sleight.jpg) | ||
|
||
* New control flow mechanisms | ||
* Automatic instrumentation | ||
* Test coverage metrics | ||
* Many other things I haven't thought of | ||
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. | ||
|
||
Stay posted for updates. | ||
### what is this good for? | ||
|
||
## License | ||
Possible uses include: | ||
|
||
Copyright (C) 2012 Zachary Tellman | ||
* language extensions | ||
* pervasive inversion-of-control transforms | ||
* automatic instrumentation | ||
* test coverage metrics | ||
* anything else you can dream up | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. | ||
### 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.0-SNAPSHOT"]` to the `:plugins` vector of your `:user` profile in `~/.lein/profiles.clj`. | ||
|
||
To use for a specific project, add `[lein-sleight "0.2.0-SNAPSHOT"]` to the `:plugins` vector in `project.clj`. | ||
|
||
--- | ||
|
||
Once this is done, define a transform in your project or one of its dependencies. | ||
|
||
```clj | ||
(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](https://github.com/ztellman/riddley). | ||
|
||
Then, in your `project.clj`, add something like this: | ||
|
||
```clj | ||
(project your-project "1.0.0" | ||
:sleight {:default {:transforms [a.namespace/reverse-everything]} | ||
:partial {:transforms [a.namespace/reverse-everything] | ||
: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 |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
(defproject lein-sleight "0.2.0-SNAPSHOT" | ||
:description "A plugin for whole-program transformations via sleight" | ||
:url "http://example.com/FIXME" | ||
:license {:name "Eclipse Public License" | ||
:url "http://www.eclipse.org/legal/epl-v10.html"} | ||
:license {:name "MIT License"} | ||
:eval-in-leiningen true | ||
:dependencies [[leinjacker "0.3.3"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
(defproject sleight "0.2.0-SNAPSHOT" | ||
:description "whole-program transformations for clojure" | ||
:dependencies [[org.clojure/clojure "1.4.0"]]) | ||
:dependencies [] | ||
:profiles {:dev {:dependencies [[org.clojure/clojure "1.5.1"] | ||
[riddley "0.1.4"]]}} | ||
:plugins [[lein-sleight "0.2.0-SNAPSHOT"]] | ||
:sleight {:default {:transforms [sleight.transform-test/make-odd]}} | ||
:test-selectors {:make-odd :make-odd | ||
:normal (complement :make-odd)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.