< :the previous in number
^ :the list in numerical order
> :the next in number
P :the previous artilce (have the same parent)
N :the next (in thread)
|<:the top of this thread
>|:the next thread
^ :the parent (reply-to)
_:the child (an article replying to this)
>:the elder article having the same parent
<:the youger article having the same parent
---:split window and show thread lists
| :split window (vertically) and show thread lists
~ :close the thread frame
.:the index
..:the index of indices
> 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