[#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:5056] Re: Perl 6 rumblings -- RFC 225 (v1) Data: S uperpositions (fwd)

From: Mathieu Bouchard <matju@...>
Date: 2000-09-22 05:27:16 UTC
List: ruby-talk #5056
> While I can't grasp a bit what's going on with superpositions, I might add
> that I'd bet there's never need for this type of RFC ([1]) for Ruby. I'm not
> talking about the subject though; we might want to implement superpositions
> in Ruby too. But in this case one has more freedom in Ruby than in Perl.

ok, let's see what's going on.

a = Any.new(1,3,6,10)
#<Any: @values=[1, 3, 6, 10]>

a is a superposition of four integers.

b = a > 5
#<Any: @values=[[false, false, true, true]]>

b is a superposition of four booleans, the results of >(5) messages to
all elements.

b.collapse
true

the final result is a OR of all booleans.

the source code:

--------8<--------cut-here--------8<--------

class Any
	def initialize(*values)
		@values = values
	end
	def method_missing(*params,&proc)
		Any.new(@values.collect {|v| v.send(*params,&proc) })
	end
	def collapse
		@values.each {|v| return true if v }
		return false
	end
end

--------8<--------cut-here--------8<--------

Of course the above code is not perfect. In particular it does not deal
with the fact that several built-in methods check for particular types,
most notably Numeric#coerce; and also the evaluator does check for
nil/false, so you can't automatically collapse on if..then, because
if..then sees any Any object as a true value.

Maybe this could be solved (partially) by having an Object#to_b that is
required to return true or false (the real ones). Maybe also an if..then
should be an Object#then_else method which is passed two blocks (which has
the advantage of allowing us to change the semantics of if/then/else
completely if needed).

My point is, although it might not be wanted to add superpositions
directly in the language, some peripheral, general-purpose features might
be desirable. 


matju


In This Thread