Ruby Core - Lambda function

Discussion in 'Ruby' started by Paul A., May 28, 2010.

  1. Paul A.

    Paul A. Guest

    Hi,

    Just a thin post in order to purpose this:

    I think it could be cool to call lambda function just like: λ

    Such as:

    a = 0
    my_while λ { a < 5 } do
    puts a
    a += 1
    end

    I think λ is more human then ->

    Regards
    --
    Posted via http://www.ruby-forum.com/.
    Paul A., May 28, 2010
    #1
    1. Advertising

  2. 2010/5/28 Paul A. <>:
    > Just a thin post in order to purpose this:
    >
    > I think it could be cool to call lambda function just like: =EB
    >
    > Such as:
    >
    > a =3D 0
    > my_while =A0=EB { a < 5 } =A0do
    > =A0 puts a
    > =A0 a +=3D 1
    > end
    >
    > I think =EB is more human then ->


    This might cause issues with encoding of the source code - I believe
    it is unspoken agreement that programming languages use 7 bit ASCII as
    least common denominator for encoding of keywords and control
    structures. And the reason is that with that convention you have the
    biggest chance of being robust against encoding differences (e.g. IIRC
    7 bit ASCII is a subset even of UTF-8 and of course all the ISO 8859
    encodings). There might even be systems that do not support an
    encoding which knows the greek lambda. This would limit portability
    of source code.

    Maybe this is a topic for ruby-core (cross posted there).

    Kind regards

    robert

    --=20
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
    Robert Klemme, May 28, 2010
    #2
    1. Advertising

  3. okay I have seen this in clojure also. sigma and likes. Can you please tell
    me how to type it ? :p

    Piyush

    2010/5/28 Robert Klemme <>

    > 2010/5/28 Paul A. <>:
    > > Just a thin post in order to purpose this:
    > >
    > > I think it could be cool to call lambda function just like: =EB
    > >
    > > Such as:
    > >
    > > a =3D 0
    > > my_while =EB { a < 5 } do
    > > puts a
    > > a +=3D 1
    > > end
    > >
    > > I think =EB is more human then ->

    >
    > This might cause issues with encoding of the source code - I believe
    > it is unspoken agreement that programming languages use 7 bit ASCII as
    > least common denominator for encoding of keywords and control
    > structures. And the reason is that with that convention you have the
    > biggest chance of being robust against encoding differences (e.g. IIRC
    > 7 bit ASCII is a subset even of UTF-8 and of course all the ISO 8859
    > encodings). There might even be systems that do not support an
    > encoding which knows the greek lambda. This would limit portability
    > of source code.
    >
    > Maybe this is a topic for ruby-core (cross posted there).
    >
    > Kind regards
    >
    > robert
    >
    > --
    > remember.guy do |as, often| as.you_can - without end
    > http://blog.rubybestpractices.com/
    >
    >
    Piyush Ranjan, May 28, 2010
    #3
  4. On 5/27/10, Paul A. <> wrote:
    > Hi,
    >
    > Just a thin post in order to purpose this:
    >
    > I think it could be cool to call lambda function just like: =EB
    >
    > Such as:
    >
    > a =3D 0
    > my_while =EB { a < 5 } do
    > puts a
    > a +=3D 1
    > end


    Honestly, why is this better than:

    a=3D0
    while a<5 do
    puts a
    a+=3D1
    end

    This way is so much less noisy and more succinct. You could even leave
    off the do.

    lambdas should not be used to replace arbitrary expressions. Only
    where you need them.

    > I think =EB is more human then ->


    Idunno. It's just some (fairly arbitrary) greek letter. I find the
    arrow a little more evocative myself.

    Putting Robert's doubts about encoding issues aside, you can already
    do this in both 1.8 and 1.9:

    #encoding: utf-8
    alias =EB lambda
    x=3D=EB{ p :foo }
    x.call #=3D> :foo

    In 1.8, you do have to pass -Ku on the command line, tho.

    I am with Piyush on the question of how you type these things, tho. My
    keyboard only has ascii on it. I'm putting off adopting unicode until
    a unicode keyboard is available.
    Caleb Clausen, May 28, 2010
    #4
  5. Paul A.

    Intransition Guest

    On May 28, 2:37=C2=A0am, "Paul A." <> wrote:
    > Hi,
    >
    > Just a thin post in order to purpose this:
    >
    > I think it could be cool to call lambda function just like: =CE=BB
    >
    > Such as:
    >
    > a =3D 0
    > my_while =C2=A0=CE=BB { a < 5 } =C2=A0do
    > =C2=A0 =C2=A0puts a
    > =C2=A0 =C2=A0a +=3D 1
    > end
    >
    > I think =CE=BB is more human then ->


    For that matter, if we're going by similarity, doesn't /\ look much
    more like =CE=BB than -> ?

    f =3D /\(x){ x < 5 }
    Intransition, May 28, 2010
    #5
  6. 2010/5/28 Caleb Clausen <>:
    > On 5/27/10, Paul A. <> wrote:
    >> Hi,
    >>
    >> Just a thin post in order to purpose this:
    >>
    >> I think it could be cool to call lambda function just like: =EB
    >>
    >> Such as:
    >>
    >> a =3D 0
    >> my_while =A0=EB { a < 5 } =A0do
    >> =A0 =A0puts a
    >> =A0 =A0a +=3D 1
    >> end

    >
    > Honestly, why is this better than:
    >
    > =A0a=3D0
    > =A0while a<5 do
    > =A0 =A0puts a
    > =A0 =A0a+=3D1
    > =A0end


    or even

    5.times do |a|
    puts a
    end

    or even

    puts (0...5).to_a

    > This way is so much less noisy and more succinct. You could even leave
    > off the do.
    >
    > lambdas should not be used to replace arbitrary expressions. Only
    > where you need them.


    Yep, fully agree.

    > Putting Robert's doubts about encoding issues aside, you can already
    > do this in both 1.8 and 1.9:
    >
    > #encoding: utf-8
    > alias =EB lambda
    > x=3D=EB{ p :foo }
    > x.call #=3D> :foo
    >
    > In 1.8, you do have to pass -Ku on the command line, tho.


    This is cool! Thanks for that.

    > I am with Piyush on the question of how you type these things, tho. My
    > keyboard only has ascii on it. I'm putting off adopting unicode until
    > a unicode keyboard is available.


    You'll need a new desk then, too - and probably a set of arm extensions. :-=
    )

    Cheers

    robert

    --=20
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
    Robert Klemme, May 28, 2010
    #6
  7. andrew mcelroy, May 28, 2010
    #7
  8. On 5/28/10, Robert Klemme <> wrote:
    > 2010/5/28 Caleb Clausen <>:
    >> I am with Piyush on the question of how you type these things, tho. My
    >> keyboard only has ascii on it. I'm putting off adopting unicode until
    >> a unicode keyboard is available.

    >
    > You'll need a new desk then, too - and probably a set of arm extensions. :)


    I meant it as mostly a joke, but I really do want a unicode keyboard
    if one could possibly exist.

    I'd be satisfied if my unicode keyboard left off chinese, japanese,
    korean, and vietnamese glyphs, since I'm very unlikely to use those.
    That should reduce the size of the keyboard by about 3/4. I'd still
    need several new desks, tho. :-/
    Caleb Clausen, May 28, 2010
    #8
  9. Paul A.

    Ken Bloom Guest

    On Fri, 28 May 2010 23:25:17 +0900, Caleb Clausen wrote:

    > On 5/28/10, Robert Klemme <> wrote:
    >> 2010/5/28 Caleb Clausen <>:
    >>> I am with Piyush on the question of how you type these things, tho. My
    >>> keyboard only has ascii on it. I'm putting off adopting unicode until
    >>> a unicode keyboard is available.

    >>
    >> You'll need a new desk then, too - and probably a set of arm
    >> extensions. :)

    >
    > I meant it as mostly a joke, but I really do want a unicode keyboard if
    > one could possibly exist.
    >
    > I'd be satisfied if my unicode keyboard left off chinese, japanese,
    > korean, and vietnamese glyphs, since I'm very unlikely to use those.
    > That should reduce the size of the keyboard by about 3/4. I'd still need
    > several new desks, tho. :-/


    I think an optimus maximus keyboard would be what you want. Set the 10
    keys on the left as modifiers to switch between different langauges.

    --Ken



    --
    Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
    Department of Computer Science. Illinois Institute of Technology.
    http://www.iit.edu/~kbloom1/
    Ken Bloom, May 28, 2010
    #9
  10. Robert Klemme wrote:
    > puts (0...5).to_a


    Pointless golf of the day:

    puts(*0...5)

    But this is even farther from the original point, which is why not have
    a more compact notation for when you need to pass more than one block to
    a method.
    Joel VanderWerf, May 28, 2010
    #10
  11. Paul A.

    Robert Dober Guest

    2010/5/28 Joel VanderWerf <>:
    > Robert Klemme wrote:
    >>
    >> puts (0...5).to_a

    >
    > Pointless golf of the day:

    I can beat you in pointlessness ;)
    >
    > puts(*0...5)

    puts *0..5
    R.
    Robert Dober, May 29, 2010
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dave
    Replies:
    0
    Views:
    316
  2. Roman Suzi
    Replies:
    13
    Views:
    591
    Bengt Richter
    Jan 7, 2005
  3. Gyoung-Yoon Noh
    Replies:
    1
    Views:
    87
    James Britt
    Dec 24, 2005
  4. Steve Dogers

    lambda vs non-lambda proc

    Steve Dogers, Mar 30, 2009, in forum: Ruby
    Replies:
    1
    Views:
    157
    Sean O'Halpin
    Mar 30, 2009
  5. Haochen Xie
    Replies:
    4
    Views:
    233
    Haochen Xie
    Mar 17, 2013
Loading...

Share This Page