https://github.com/bfontaine/minimaliterals
Ruby-like %-literals in Clojure
https://github.com/bfontaine/minimaliterals
clojure library macros
Last synced: 8 months ago
JSON representation
Ruby-like %-literals in Clojure
- Host: GitHub
- URL: https://github.com/bfontaine/minimaliterals
- Owner: bfontaine
- License: epl-1.0
- Created: 2014-02-19T23:23:39.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-02-23T19:53:28.000Z (over 12 years ago)
- Last Synced: 2025-03-23T23:43:41.285Z (over 1 year ago)
- Topics: clojure, library, macros
- Language: Clojure
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minimaliterals
[](https://travis-ci.org/bfontaine/Minimaliterals)
[](https://coveralls.io/r/bfontaine/Minimaliterals)
**minimaliterals** is an experimental library which brings Ruby-like
[%-literals][1] to Clojure. This is only for fun with macros, use it at your
own risk!
[1]: https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#The_.25_Notation
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:
```clj
[minimaliterals "0.1.0"]
```
Then use it:
```clj
(ns your-namespace
; ...
(:use minimaliterals.core))
; ...
(def names (%w henry james jayne))
```
## Caveats
No interpolation is done, this means that the following code:
```clj
(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.