Ok - ClojureScript has an undefined? function that works like:

ClojureScript:cljs.user> (def v)

ClojureScript:cljs.user> (undefined? v)
true
ClojureScript:cljs.user> (def w nil)
nil
ClojureScript:cljs.user> (undefined? w)
false
ClojureScript:cljs.user> (defn f [v] (if (undefined? v) :no-value v))
#<function f(v){
if((void 0 === v))
{return "\uFDD0:no-value";
} else
{return v;
}
}>
ClojureScript:cljs.user> (f z)
:no-value
ClojureScript:cljs.user> (f 1)
1
ClojureScript:cljs.user> (f y)
nil


which indicates that I can use that scheme to pass and detect "no-value" 
arguments in cljs.

Isn't it great to answer your own Qs ;-)

-FS.



On Jan 14, 2013, at 7:47 PM, Frank Siebenlist <frank.siebenl...@gmail.com> 
wrote:

> 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 <frank.siebenl...@gmail.com> 
> 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 <tbaldri...@gmail.com> 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 
>>> <frank.siebenl...@gmail.com> 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 clojure@googlegroups.com
>>> Note that posts from new members are moderated - please be patient with 
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+unsubscr...@googlegroups.com
>>> 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 clojure@googlegroups.com
>>> Note that posts from new members are moderated - please be patient with 
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+unsubscr...@googlegroups.com
>>> 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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to