I'm trying to do some processing of values passed in a plist. Processing is quite similar: get a value, convert it to number if necessary, check if within bounds and if yes, return a string with that number, properly formatted.
Thus, I decided to create a list of actions, and then map through them, picking up non-nil values:
(defun knl--initialize-numerics (info)
"Makes a string containing initialization of numerical parameters"
;; logic is: convert to number, if satisfies condition print it, skip otherwise
(let* ((num-inits '((:knl-width 'identity (-partial '> 0) "%d")
(:knl-height 'identity (-partial '> 0) "%d")
(:knl-margin 'string-to-number (-partial '>= 0) "%.2f")
(:knl-min-scale 'string-to-number (-partial '> 0) "%.2f")
(:knl-max-scale 'string-to-number (-partial '> 0) "%.2f"))))
(--map
;; function
(-when-let* (((sym conv cond frm) it)
(oval (plist-get info sym))
(val (funcall conv oval))
(matches? (funcall cond val))
(name (s-lower-camel-case (s-chop-prefix ":knl-" (symbol-name sym))))
(formatted (format frm val)))
)
val
)
;; data
num-inits)))
The above code fails at (val (funcall conv oval))
in ielm
when I try to execute the following:
ELISP> (knl--initialize-numerics '(:knl-width 10 :knl-height 0 :knl-margin 0))
*** Eval error *** Invalid function: (quote identity)
I was trying the same with a simple function, and it works:
ELISP> (let ((conv 'identity) (val 5)) (funcall conv val ))
5 (#o5, #x5, ?\C-e)
Why doesn't it then work in a more complex example? Is that because of some dash.el
magic?