Devin Mullins <twifkak / comcast.net> writes:

>>> BTW, change *b to b, in my code.
>>
>> Why?
>
> [[1,2,3],[4,5,6],[7,8,9]] * :+ should => [1,2,3,4,5,6,7,8,9]

   class Symbol
      def to_proc
        lambda { |a, *b| a.send(self, *b) } end end

   [[1,2,3],[4,5,6],[7,8,9]].inject(&:+) #=> [1..9].to_a

   class Symbol
      def to_proc
        lambda { |a, b| a.send(self, b) } end end

   [[1,2,3],[4,5,6],[7,8,9]].inject(&:+) #=> [1..9].to_a

It only matters when the iterator (°∆inject°«, in this case)
passes more than two arguments to the block.  ...right?

>> Random aside:  In mathematics, a non-commutable +
>> operator is pretty damn near unthinkable, wheras in
>> computer science it's completely normal.  I think that's
>> kind of interesting.
>
> Well, in Ruby it's completely normal. I can't think of any
> other language that does that by default...

There are lots and lots and lots of examples.  To choose
just one, Java overloads + non-commutatively for strings:

   ("foo" + "bar").equal("bar" + "foo") // => false

> One thing that's okay in programming but not in math is
> that 5/2 == 2. :)

It's not okay with me. :-)

I'd much rather have the °∆/°« operator not perform any
truncation, and use °∆5.div 2°« to get integer division.

>> Ah.  In light of this thread, I'm actually a little
>> curious about what other insights one might get from
>> learning APL.
>
> Not much, I don't think. It's a language whose primary use
> is processing lists and matrices of numbers, and whose
> sole focus is absolute terseness at the expense of
> readability in any sense of the word. But hey, maybe I'm
> being pessimistic. I shouldn't prevent you from a
> potential learning experience:
>
> http://en.wikipedia.org/wiki/APL_programming_language
> http://www.thocp.net/software/languages/apl.htm
> http://www.thefreecountry.com/compilers/apl.shtml
> http://www.engin.umd.umich.edu/CIS/course.des/cis400/apl/apl.html
> http://www.users.cloud9.net/~bradmcc/APL.html
> http://www.acm.org/sigs/sigapl/

Hmm... maybe some day. :-)

>> Yeah.  Having been bitten a few times by the
>> double-aliasing bug that comes into play when a file that
>> uses the °»alias and redefine°… idiom is loaded twice, ...
>
> I'm eager to see when Behaviors is ready for prime-time.
> Ruby needs more support for this sort of thing.

I haven't heard of Behaviors before, but it seems
interesting.  I'm going to read up on them, thanks.

> Also, what do you think of an 'original' keyword for when
> you redefine a method (assuming that Behaviors solves your
> loaded-twice problem)?
>
> class String
>   def gsub(*a)
>     if a.size == 1 then original
>     else original(a[0]).gsub(a[1..-1])
>     end
>   end
> end
>
> One could use the original keyword like one uses the
> super keyword.

That's a great idea.  I really like it.  The idiom is so
common and ugly that it definitely could use some sugar.

The semantics are straightforward, too:  Only redefine a
method when its current body differs from the new one, and
give the redefined method a reference to the old one,
accessible through °∆original°«.  (For efficiency, the
original method should probably only be saved if the new
method uses the °∆original°« keyword.)

-- 
Daniel Brockman <daniel / brockman.se>

    So really, we all have to ask ourselves:
    Am I waiting for RMS to do this?   --TTN.