[#4766] Wiki — "Glen Stampoultzis" <trinexus@...>

21 messages 2000/09/04
[#4768] RE: Wiki — "NAKAMURA, Hiroshi" <nahi@...> 2000/09/04

Hi, Glen,

[#4783] Re: Wiki — Masatoshi SEKI <m_seki@...> 2000/09/04

[#4785] Re: Wiki — "NAKAMURA, Hiroshi" <nakahiro@...> 2000/09/05

Howdy,

[#4883] Re-binding a block — Dave Thomas <Dave@...>

16 messages 2000/09/12

[#4930] Perl 6 rumblings -- RFC 225 (v1) Data: Superpositions — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/09/15

[#4936] Ruby Book Eng. translation editor's questions — Jon Babcock <jon@...>

20 messages 2000/09/16

[#5045] Proposal: Add constants to Math — Robert Feldt <feldt@...>

15 messages 2000/09/21

[#5077] Crazy idea? infix method calls — hal9000@...

This is a generalization of the "in" operator idea which I

17 messages 2000/09/22

[#5157] Compile Problem with 1.6.1 — Scott Billings <aerogems@...>

When I try to compile Ruby 1.6.1, I get the following error:

15 messages 2000/09/27

[ruby-talk:5036] Re: A QuantumSuperposition Proposal for Ruby

From: Yasushi Shoji <yashi@...>
Date: 2000-09-20 21:06:13 UTC
List: ruby-talk #5036
At Thu, 21 Sep 2000 00:12:58 +0900,
Huayin Wang <wang@rjka.com> wrote:

> I probably misunderstand your comments here, but I am not limiting it 
> to only Numeric. when I tried the following, it works!
> 
> p ['a','c'].any > 'b'         # true
> p ['a','c'].all > 'b'         # false

it works because class String has a method '>'.  i guess what I meant
was that what's the use of class Quantum if internal object doesn't
have methods like '>', '<', 'size'?  is it expecting instances of
class which include Comparable?

[...]

> however, I can't do it for string
> 
> p 'b' > ['a','c'].any
> p 'b' > ['a','c'].all

i guess string doesn't call coerce.

> I do not understand.  and using coerce rather than my original 
> implementation give different results:
> 
> Using my original implementation:
> p [1,2,3].any < [2,5,6].all     # true
> 
> It print out "false" using yashi's implementation.

hmm.. swapping doesn't work, huh ;p

following code prints 'true' as the original.

somehow if i think more about quantum, blurer it gets.  i'll just wait
and see what came out.

regards,
--
        yashi

  def coerce(o)
    return Quantum.new([o], :any?), self
  end
  def >(o)
    case o
    when self.type
      o.states.send(o.method) { |x| self > x }
    when Numeric
      @states.send(@method) { |x| x > o }
    when String
      @states.send(@method) { |x| x > o }
    else
      raise "unexpected object of class '#{o.type.to_s}' for the argument of '>'"
    end
  end
  def <(o)
    case o
    when self.type
      o.states.send(o.method) { |x| self < x }
    when Numeric
      @states.send(@method) { |x| x < o }
    when String
      @states.send(@method) { |x| x < o }
    else
      raise "unexpected object of class '#{o.type.to_s}' for the argument of '<'"
    end
  end
  protected
  def states
    @states
  end
  def method
    @method
  end

require 'quantum'

q = Quantum.new(['a','c'], :all?)
p (q > 'b')

q = Quantum.new(['a','c'], :any?)
p (q > 'b')

q = Quantum.new([1,2,3], :any?)
p (2 > q)

q = Quantum.new([1,2,3], :all?)
p (2 > q)


a = Quantum.new([1,2,3], :any?)
b = Quantum.new([2,5,6], :all?)

p (a < b)

q = Quantum.new(['a','c'], :any?)
p ('b' > q)

In This Thread

Prev Next