For clojure I came up with the following alternative using an unbound var: user=> (def v) #'user/v user=> (defn f [x] (if (var? x) (if (bound? x) x :no-value) x)) #'user/f user=> (f v) #<Unbound Unbound: #'user/v> user=> (f #'v) :no-value user=> (f #'map) #'clojure.core/map user=> (type (f v)) clojure.lang.Var$Unbound user=>
which would indicate that I could pass an unbound var as the argument to indicate a "no-value" value, which I can either detect thru the type or the bound? test. However, next issue is how to do this in ClojureScript as we do not have any vars and therefor no unbound vars…? -FS. On Jan 14, 2013, at 7:07 PM, Frank Siebenlist <[email protected]> wrote: > Understood. > > … but shouldn't it be a standardized constant for the whole community to use > to avoid any interoperability issues and many reinvented wheels? > > The concept of no-value versus nil is a pretty basic one - there must be > better solutions (re)invented many times over ;-) > > -FS. > > > On Jan 14, 2013, at 5:23 PM, Timothy Baldridge <[email protected]> wrote: > >> It's fairly common in situations like this to use a namespaced keyword. For >> instance ::unknown (which is short for my.namespace/unknown). >> >> >> On Mon, Jan 14, 2013 at 6:06 PM, Frank Siebenlist >> <[email protected]> wrote: >> I'm using those watcher-fns that get called when the watched ref changes, >> and the watcher-fn gets passed the old-value and the new-value. >> >> Now, nil is a proper value for a key-value and well as a val-value in a map, >> so passing nil does not give you the info whether or not an old-value >> existed or not, or whether a new-value is nil or no-value. >> >> With the getter fn: (get m k no-value-here), you have the option to pass >> this no-value-here argument which gets returned if there was no value - this >> allows you to distinguish nil from "no-value". However, in the watcher-fn >> you cannot pass such a no-value argument. >> >> One possible solution would be to define a well-know URI for the value of >> "no-value" - something like for example: >> "uri:http://clojure.org/uri/no-value", or some other standardized constant. >> >> Any other/better suggestions? >> >> Thanks, FrankS. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to [email protected] >> Note that posts from new members are moderated - please be patient with your >> first post. >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> >> >> >> -- >> “One of the main causes of the fall of the Roman Empire was that–lacking >> zero–they had no way to indicate successful termination of their C programs.” >> (Robert Firth) >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to [email protected] >> Note that posts from new members are moderated - please be patient with your >> first post. >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
