Beginning of a type system
Posted: November 20th, 2010 | Author: Mars | Filed under: Design, Progress, Syntax | Comments OffLast night’s checkin added a new binary operator: has lets you inquire about a container’s attributes. The has operator has the same precedence as the comparison operators. Its left operand must be a container and its right operand may be any value. The result is a boolean, which is true if looking up the value in the container would result in a non-exceptional value, false if the lookup would fail.
Combining this with the new symbol-literal syntax lets you ask whether a given object implements some method:
if foo has :bar:
foo->bar(42)
end if
Testing for a set of related methods lets you determine whether an object implements some interface:
function stack?(foo):
result = foo has :push
result = result and foo has :pop
result = result and foo has :head
end stack?