Skip to content

bfontaine/Minimaliterals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

minimaliterals

Build Status Coverage Status

minimaliterals is an experimental library which brings Ruby-like %-literals to Clojure. This is only for fun with macros, use it at your own risk!

The table below summarizes the syntax:

Ruby Clojure Result
%w[foo bar] (%w foo bar) '("foo" "bar")
%q[foo bar] (%q foo bar) "foo bar"
%r[fo+ ?] (%r fo+ ?) #"fo+ ?"
%i[foo bar] (%i foo bar) '(:foo :bar)

Due to the use of %, using these macros in short-form anonymous functions won’t work (e.g. #(identity (%w a b c)) will throw an error at compile-time).

Usage

Add it as a dependency:

[minimaliterals "0.1.0"]

Then use it:

(ns your-namespace
  ; ...
  (:use minimaliterals.core))

; ...

(def names (%w henry james jayne))

Caveats

No interpolation is done, this means that the following code:

(let [x "yo"]
  (%w x y z))

would give '("x" "y" "z") and not '("yo" "y" "z").

License

Copyright © 2014 Baptiste Fontaine

Distributed under the Eclipse Public License either version 1.0 or any later version.