I would recommend _against_ using the same parameter name multiple times
like this, for the confusion in people's minds that it can easily create.
If you avoid this practice, then it is irrelevant why the last value is
used versus an earlier one.

The foo2 function works for the same reason that foo works, because '_' is
just another parameter name, no more or less special to the compiler than
the parameter name 'arg1' or 'f'.

Andy

On Sat, Jun 17, 2017 at 2:01 PM, Gregg Reynolds <d...@mobileink.com> wrote:

>
>
> On Jun 17, 2017 3:36 PM, "Andy Fingerhut" <andy.finger...@gmail.com>
> wrote:
>
> Consider this Clojure 1.8.0 REPL session:
>
> user=> (defn foo [a a] [a a])
>
> #'user/foo
>
> ser=> (foo 1 2)
>
> [2 2]
>
> user=> (defn foo2 [_ _] [_ _])
>
> #'user/foo2
>
> user=> (foo2 1 2)
>
> [2 2]
>
>
> This is the sense in which _ is just another function parameter name, no
> more or less special to the compiler than the parameter name 'a'.  There is
> no requirement in the Clojure compiler that parameter names are unique.
>
>
> thanks.  tried to do that on some of the online clj thingies, no luck.
>
> personally i view this as one of those clojure wierdisms that annoy newbs.
>  very counter-intuitive, imho.  why shouldn't the 1st arg be used?  and
> your foo2 - the fn definition, strictly speaking, makes no sense. if it
> works, i think we need to explain explicitly why.  maybe not in the section
> on '_', but somewhere.
>
> Andy
>
> On Sat, Jun 17, 2017 at 12:16 PM, Gregg Reynolds <d...@mobileink.com>
> wrote:
>
>>
>>
>> On Jun 17, 2017 1:55 PM, "Timothy Baldridge" <tbaldri...@gmail.com>
>> wrote:
>>
>> Anonymous implies there might be some sort of auto gen going on (as there
>> is with anonymous functions), Irrelevant has my vote therefore. The other
>> characteristics are a side-effect of it being a naming convention (with no
>> official support by the compiler).
>>
>>
>> yeah, i could go either way, although i might change "var" to "arg" - is
>> '_' ever a var?  actually i'm thinking "nonce arg" would be more accurate,
>> but then i'm a naming fanatic so take it with a grain of salt.
>>
>> Maybe that could be pointed out in greater detail. So maybe an edit along
>> the lines of:
>>
>> "Note: _ does not have special functionality in the compiler, it is seen
>> the same as any other local or arg, therefore the same rules of uniqueness
>> and precedence apply with _ as they would with any other symbol"
>>
>>
>> i might not understand the rules but my understanding is that '_' (as an
>> arg) is outside of the uniqueness (obviously) and precedence rules.  i'm
>> not understanding the point of your suggested edit, i guess.  thinking from
>> a newbie perspective.  are you saying that each '_' gets a gen-sym, so each
>> ends up being unique?
>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to