This page is no longer maintained — Please continue to the home page at www.scala-lang.org

1::2::Nil sort >

4 replies
Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.

I remember in C++, a pointer to a method could be passed around as a function
with 2 arguments, simply because methods are actually functions taking an
implicit first argument (maybe my memory doesn't serve me well anymore).

The question is: is there (or could there be) a syntax to get a method as a
function of 2 arguments? so I could simply write this:

1::2::NIl sort Int.>

or, if the compiler gets even smarter, the even more interesting:

1::2::NIl sort >

Right now I have to do this

scala> def > (i:Int,j:Int) = i > j
$greater: (i: Int,j: Int)Boolean

Worth considering?

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Latest cool toy: http://scripster.codewitter.com
Follow me: http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter , http://github.com/razie GitHub .

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: 1::2::Nil sort >

On Thu, Apr 29, 2010 at 06:39:10AM -0700, Razvan Cojocaru wrote:
> The question is: is there (or could there be) a syntax to get a method
> as a function of 2 arguments? so I could simply write this:
>
> 1::2::NIl sort Int.>

scala> 1::2::Nil sort (_ > _)
warning: there were deprecation warnings; re-run with -deprecation for details
res0: List[Int] = List(2, 1)

Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.
Re: 1::2::Nil sort >

good point - this syntax is simple enough. i was hoping to avoid the ()
part...but it wouldn't be shorter.

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Latest cool toy: http://scripster.codewitter.com
Follow me: http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter , http://github.com/razie GitHub .

Arthur Peters 2
Joined: 2009-01-10,
User offline. Last seen 42 years 45 weeks ago.
Re: 1::2::Nil sort >

You can already write:

(1::2::Nil).sort(_>_)

The underscores define where arguments go in the expression.

-Arthur (sent from phone)

On Apr 29, 2010 9:39 AM, "Razvan Cojocaru" <razie [at] razie [dot] com> wrote:


I remember in C++, a pointer to a method could be passed around as a function
with 2 arguments, simply because methods are actually functions taking an
implicit first argument (maybe my memory doesn't serve me well anymore).

The question is: is there (or could there be) a syntax to get a method as a
function of 2 arguments? so I could simply write this:

1::2::NIl sort Int.>

or, if the compiler gets even smarter, the even more interesting:

1::2::NIl sort >

Right now I have to do this

scala> def > (i:Int,j:Int) = i > j
$greater: (i: Int,j: Int)Boolean

Worth considering?



-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Latest cool toy: http://scripster.codewitter.com
Follow me:  http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter ,  http://github.com/razie GitHub .

--
View this message in context: http://scala-programming-language.1934581.n4.nabble.com/1-2-Nil-sort-tp2075468p2075468.html
Sent from the Scala - Debate mailing list archive at Nabble.com.

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: 1::2::Nil sort >
What about1::2::Nil sort _.>
?
Plain '>' can't work in Scala. What would the following do?def > : (Int,Int)=>Int  =  ...1::2::Nil sort >

On Thu, Apr 29, 2010 at 9:39 AM, Razvan Cojocaru <razie [at] razie [dot] com> wrote:

I remember in C++, a pointer to a method could be passed around as a function
with 2 arguments, simply because methods are actually functions taking an
implicit first argument (maybe my memory doesn't serve me well anymore).

The question is: is there (or could there be) a syntax to get a method as a
function of 2 arguments? so I could simply write this:

1::2::NIl sort Int.>

or, if the compiler gets even smarter, the even more interesting:

1::2::NIl sort >

Right now I have to do this

scala> def > (i:Int,j:Int) = i > j
$greater: (i: Int,j: Int)Boolean

Worth considering?



-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Latest cool toy: http://scripster.codewitter.com
Follow me:  http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter ,  http://github.com/razie GitHub .

--
View this message in context: http://scala-programming-language.1934581.n4.nabble.com/1-2-Nil-sort-tp2075468p2075468.html
Sent from the Scala - Debate mailing list archive at Nabble.com.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland