shorter notation for functions and regexes
This commit is contained in:
parent
026f911be2
commit
d1a02ca7e3
3 changed files with 12 additions and 4 deletions
10
README.md
10
README.md
|
|
@ -64,14 +64,18 @@ $ echo '"babashka"' | bb '(re-find (re-pattern "b.b.*") *in*)'
|
||||||
"babashka"
|
"babashka"
|
||||||
```
|
```
|
||||||
|
|
||||||
Functions are written using the reader tag `#bb/fn`. Currently up to three
|
Functions are written using the reader tag `#f`. Currently up to three
|
||||||
arguments are supported.
|
arguments are supported.
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ echo '3' | bb '(#bb/fn (+ %1 %2 %3) 1 2 *in*)'
|
$ echo '3' | bb '(#f (+ %1 %2 %3) 1 2 *in*)'
|
||||||
6
|
6
|
||||||
|
```
|
||||||
|
|
||||||
$ ls | bb --raw '*in*' | bb '(filterv #bb/fn (re-find (re-pattern "reflection") %) *in*)'
|
Regexes are written using the reader tag `#r`.
|
||||||
|
|
||||||
|
``` shellsession
|
||||||
|
$ ls | bb --raw '*in*' | bb '(filterv #f (re-find #r "reflection" %) *in*)'
|
||||||
["reflection.json"]
|
["reflection.json"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,9 @@
|
||||||
%3 z
|
%3 z
|
||||||
(interpret elt x))) form)))
|
(interpret elt x))) form)))
|
||||||
|
|
||||||
|
(defn read-regex [form]
|
||||||
|
(re-pattern form))
|
||||||
|
|
||||||
(defn apply-fn [f in args]
|
(defn apply-fn [f in args]
|
||||||
(let [args (map #(interpret % in) args)]
|
(let [args (map #(interpret % in) args)]
|
||||||
(apply f args)))
|
(apply f args)))
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
{bb/fn babashka.interpreter/read-fn}
|
{f babashka.interpreter/read-fn
|
||||||
|
r babashka.interpreter/read-regex}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue