Clojure Parameters with Optional Flags -
What's the best way to implement keywords as an alternative flag for a function? I want to call the function such as:
(myfunction 5) (myfunction 6: do-this) (myfunction 3: go-here) (myfunction 2: two-this: what-is) Using defn, I can define a function such as: (myfunction [value and flags] ...)
But flag
becomes a list. I can write my own function to search the list, but such a function is not included in the core library, So I think it's idiotic is.
What I'm using now:
(defn flag-set? [List flag] (not (empty? (Filter # (= flag%) list ) (Defn flag-add [list flag] (opposition flag list)) (defn flag delete [list flag] (filter # (not = flag%) list))
Lists (as well as vectors and maps) are not a good option for data structure for value-based lookup (linear time) That clojure.core does not have such functions.
Set via "What is" If it provides a fast value-based lookup, then about
(defn foo [value and flags] (let's [flags] (if it's included? Flags: Add-one) (ink value)))
If no more than one flag, then you can use demolition in such a way:
(Defn foo [value & amp; [flag]] ...)
Comments
Post a Comment