This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-14
Channels
- # beginners (74)
- # boot (23)
- # braid-chat (7)
- # cider (5)
- # clara (3)
- # cljsjs (17)
- # cljsrn (1)
- # clojure (105)
- # clojure-austin (9)
- # clojure-new-zealand (34)
- # clojure-poland (2)
- # clojure-russia (177)
- # clojure-uk (41)
- # clojure-ukraine (2)
- # clojurescript (130)
- # component (1)
- # core-async (2)
- # core-matrix (6)
- # cursive (7)
- # data-science (103)
- # datomic (24)
- # emacs (15)
- # funcool (4)
- # hoplon (21)
- # immutant (151)
- # ldnclj (76)
- # melbourne (1)
- # off-topic (8)
- # om (152)
- # om-next (1)
- # onyx (26)
- # parinfer (38)
- # re-frame (13)
- # reagent (14)
- # spacemacs (1)
- # vim (92)
- # yada (1)
I have this macro
(defmacro defv [i c v]
`(defc= ~i {:valid? (if (~v ~c) true false)
:value ~c}))
I use it like this : (defv form-fullname-valid? form-name (validate-regexp #"^(.*\s+.*)+$"))
I would like another macro defnv
where I could use like this instead :
(defnv form-fullname-valid? [cell-name] (validate-regexp #"^(.*\s+.*)+$"))
(form-fullname-valid? form-name)
What would be the macro then?
Thanks in advance!
@leontalbot: instead of using macros you might consider building validations functionally with the formula
function
What is the formula fn?
i will try to translate your code, 1 sec
ah, much thanks!
so formula
is a function that "lifts" a function to the "cell level"
for example: (def add1 (formula (fn [x] (inc x))))
it takes a function of n args, and returns a function expecting n cells as args
(def x (cell 123)) ((formula println) x) (swap! x inc)
((formula println) x)
is synonymous with (cell= (println x)
and is what cell=
expands out to, more or less
(defn make-validator [pred] (formula (fn [val] {:valid? (boolean (pred val)) :value val})))
^^ returns a function that takes a cell and returns a formula cell of (fn [val] ...)
there isn't anything fundamental you can do with defc=/cell=
that you can't do with formula
it's in JS syntax but i wrote about using javelin from JS, which is necessarily through formula
since JS doesn't have macros - http://adzerk.com/blog/2015/06/splint-functional-first-aid-jquery/
formula is at javelin.core/formula btw
ok i gotta go, bbl
Thank you @alandipert !!
no prob! yeah working directly with formula is lots of fun