[swift-evolution] [Proposal] Automating Partial Application via Wildcards

Matthew Johnson matthew at anandabits.com
Tue Feb 2 13:42:44 CST 2016


> On Feb 2, 2016, at 1:31 PM, Joe Groff <jgroff at apple.com> wrote:
> 
> 
>> On Feb 2, 2016, at 11:14 AM, Matthew Johnson <matthew at anandabits.com <mailto:matthew at anandabits.com>> wrote:
>> 
>> I know there is concern about overloading the semantics of `_` which is unfortunate as IMO it is the best symbol to serve as a placeholder.  I wonder if there has been confusion about the semantics in practice in languages like Scala where it is used in both ways.  Is there any evidence that this has been a problem?
> 
> Not a super scientific study, but if you google "scala underscore", several of the results on the first page indicate confusion or bewilderment:
> 
> Scala _ [underscore] magic · Anantha Kumaran <https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj-08ju59nKAhWj26YKHRuVBh8QFggdMAA&url=http%3A%2F%2Fananthakumaran.in%2F2010%2F03%2F29%2Fscala-underscore-magic.html&usg=AFQjCNEbIIoppVNYAjr6wqxL4byR9I1fAw&sig2=Hlw6hEFfsPqvlDvEFaDoyQ>
> 
> What are all the uses of an underscore in Scala? - Stack ... <https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwj-08ju59nKAhWj26YKHRuVBh8QFggjMAE&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F8000903%2Fwhat-are-all-the-uses-of-an-underscore-in-scala&usg=AFQjCNHVNCJVosr0IzZYmh8pJRdnXTnf6g&sig2=vqWgzaddf2kEkWrdgFQuoQ&bvm=bv.113034660,d.dGY>
> 
> Scala dreaded underscore - SlideShare <https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0ahUKEwj-08ju59nKAhWj26YKHRuVBh8QFggqMAI&url=http%3A%2F%2Fwww.slideshare.net%2Fnormation%2Fscala-dreaded&usg=AFQjCNEs5fGA4e8NsU10--FKfOyga8aEaA&sig2=mlWWAnJgFVxSpA4UtA2wyw>
> 
> underscore confusion | The Scala Programming Language <http://www.scala-lang.org/old/node/2916.html>
> 

Interesting.  It looks like Scala takes this to a crazy extreme.  I can definitely see why the core team is cautious about avoiding this mistake.  

The example in the last link you shared is a pretty strong argument for avoiding partial application syntax (regardless of placeholder).  It took me a minute to see what was happening there, while it would have been immediately clear with closure braces.

The thing I like about _ as a placeholder is the visual whitespace it leaves.  It looks like a “hole” in the expression.  I wish there was some other unclaimed symbol with that attribute.  

It would be nice if we could find something better than $.  The best argument in favor of that is precedent in other languages, but it comes at the cost of being noisy enough to impede readability IMO.

-Matthew

> -Joe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160202/710e96bf/attachment.html>


More information about the swift-evolution mailing list