GithubHelp home page GithubHelp logo

riddley's Introduction

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.

riddley's People

Contributors

alexcoventry avatar bmabey avatar brandonbloom avatar collinalexbell avatar dm3 avatar immoh avatar micha avatar trptcolin avatar ztellman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.