?-> sounds potentially useful to me, but let me also point out that
> (let [person (get-the-person)]
> (when-not (nil? person)
> (let [address (.getAddress person)]
> (when-not (nil? address)
> (let [street (.getStreet address)]
> (when-not (nil? street)
> (do-something-finally-with-street street)))))
>
you could simplify the above to:
(when-let [person (get-the-person)]
(when-let [address (.getAddress person)]
(when-let [street (.getStreet address)]
(do-something-finally-with-street street))))
Not quite
(?-> (get-the-person) #(.getAddress %) #(.getStreet %) do-something)
but it's halfway there at least.
Info on contributing is here:
http://clojure.org/contributing
The first step is to get your CA signed and in the mail.
Thanks,
Jason
> * Concerning the name to give to this function : maybe ->? instead
> of ?->, if you think we can live with this "violation" to the
> predicate convention ?
I like these:
.?.
-?>
They fit with the criteria that Rich laid down in the other thread
(paraphrasing):
neither a leading nor a trailing question mark use
These spellings fit that rule and I also like them in their own right.
--Steve
Given a choice between the two, I'd choose -?>
--
R. Mark Volkmann
Object Computing, Inc.
> Given a choice between the two, I'd choose -?>
The proposal was for naming "nil-safe" versions of the existing .. and
-> functions.
(-> nil (. toString)) ==> NullPointerException
(-?> nil (. toString)) ==> nil
(.. nil (toString)) ==> NullPointerException
(.?. nil (toString)) ==> nil
Note: these are just simple examples. The point isn't the one
argument, literal nil case, but the case where many operations are
"chained" or "threaded" and at each point the propagated result may be
nil.
--Steve
As was pointed out to me recently, http://clojure.org/reader says:
"Symbols beginning or ending with '.' are reserved by Clojure."
So, is .?. not a symbol (because it's called at compile time and at
runtime there is no such thing as .?.)? i.e. what exactly is the
definition of a symbol, and do the names of macros count?
> clojure.contrib.core/.?.
> clojure.contrib.core/-?>
--
Michael Wood <esio...@gmail.com>
> As was pointed out to me recently, http://clojure.org/reader says:
>
> "Symbols beginning or ending with '.' are reserved by Clojure."
>
> So, is .?. not a symbol (because it's called at compile time and at
> runtime there is no such thing as .?.)? i.e. what exactly is the
> definition of a symbol, and do the names of macros count?
clojure.contrib.core/.?. is a symbol. Thanks for pointing out that it
is one that's reserved to Clojure.
The reference you gave is the canonical documentation for symbols in
Clojure. Symbols in Clojure are used to name things including macros.
The name clojure.core/.. works and its name isn't a problem because
it's part of Clojure. The case of ".?." is a little unusual (regarding
using this kind of name) in that it's named as a variation of ".." for
the purpose of proposing it as a possible addition to Clojure at some
point.
If we can't get Rich's blessing for this name to be part of contrib,
we'll rename it.
Rich, should we rename clojure.contrib.core/.?. to avoid using a name
reserved to Clojure?
--Steve
Am 22.03.2009 um 20:45 schrieb Stephen C. Gilardi:
> clojure.contrib.core/.?. is a symbol. Thanks for pointing out that
> it is one that's reserved to Clojure.
>
> Rich, should we rename clojure.contrib.core/.?. to avoid using a
> name reserved to Clojure?
I'd like to throw in another thought:
Is .?. necessary? -> does the same job as .. by
virtue of the .method notation, but is more general.
So, why not get rid of .. and .?. completely?
Sincerely
Meikel
> Is .?. necessary? -> does the same job as .. by
> virtue of the .method notation, but is more general.
> So, why not get rid of .. and .?. completely?
That sounds right to me, Meikel. I'm in favor of keeping only -?> .
--Steve
Might I suggest "maybe->" ? This function has a strong similarity to
the Maybe monad in Haskell and similar languages.
"and->" would be another less Haskelly candidate, and is reminiscent
of Scheme's "and-let*" which is also sort-of similar.
Best,
Graham