Clojurians
#hoplon
<
2016-03-14
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

leontalbot13:03:33

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)

leontalbot13:03:15

What would be the macro then?

leontalbot13:03:04

Thanks in advance!

alandipert16:03:56

@leontalbot: instead of using macros you might consider building validations functionally with the formula function

leontalbot16:03:23

What is the formula fn?

alandipert16:03:30

i will try to translate your code, 1 sec

leontalbot16:03:37

ah, much thanks!

alandipert16:03:44

so formula is a function that "lifts" a function to the "cell level"

alandipert16:03:15

for example: (def add1 (formula (fn [x] (inc x))))

alandipert16:03:30

it takes a function of n args, and returns a function expecting n cells as args

alandipert16:03:39

(def x (cell 123)) ((formula println) x) (swap! x inc)

alandipert16:03:07

((formula println) x) is synonymous with (cell= (println x) and is what cell= expands out to, more or less

alandipert16:03:51

(defn make-validator [pred] (formula (fn [val] {:valid? (boolean (pred val)) :value val})))

alandipert16:03:59

^^ returns a function that takes a cell and returns a formula cell of (fn [val] ...)

alandipert16:03:11

there isn't anything fundamental you can do with defc=/cell= that you can't do with formula

alandipert16:03:46

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/

alandipert16:03:28

formula is at javelin.core/formula btw

alandipert16:03:32

ok i gotta go, bbl

leontalbot16:03:50

Thank you @alandipert !!

alandipert17:03:59

no prob! yeah working directly with formula is lots of fun