S
stevetuckner
I want to start a discussion about two things that Matz talked about at
the rubycon. Dave Thomas suggested that we could get Matz' anonymous
function by using "def" without a name. Others suggested that if def
returned a method object, then annotations could be applied to that
object. So here goes my suggestions. As they stand, they are not even
parseable by Ruby, but lets start talking about it anyway.
Anonymous functions:
x = def (a=1,b=2) { ... }
y = def(a,b=3) begin
.....
end
Annotated functions:
class A
def foo(a, b)
.visibility rivate # how can this be parsed? (the above
line has no trailing marker to signal it as one expression
.returns Integer
begin
....
end
def foo2(a, b).visibility(private).returns(Integer) { ... }
f3 = def foo3(a,b)
end
f3.visibilityprivate).returns(Integer)
Anonymous, Annotated functions
x = def (a, b).visibility(private).returns(Integer) { ... }
y = def (a, b) { ... }
y.visibilityprivate) # apply annotations later
y.returnsinteger)
where for anonation examples:
class Method
def visibility(v)
@annotations[:visibility] = v
return self
end
def returns(r)
@annotations[:returns] = v
return self
end
end
Please rake me over the coals because I am so ignorant ;-)
Steve Tuckner
the rubycon. Dave Thomas suggested that we could get Matz' anonymous
function by using "def" without a name. Others suggested that if def
returned a method object, then annotations could be applied to that
object. So here goes my suggestions. As they stand, they are not even
parseable by Ruby, but lets start talking about it anyway.
Anonymous functions:
x = def (a=1,b=2) { ... }
y = def(a,b=3) begin
.....
end
Annotated functions:
class A
def foo(a, b)
.visibility rivate # how can this be parsed? (the above
line has no trailing marker to signal it as one expression
.returns Integer
begin
....
end
def foo2(a, b).visibility(private).returns(Integer) { ... }
f3 = def foo3(a,b)
end
f3.visibilityprivate).returns(Integer)
Anonymous, Annotated functions
x = def (a, b).visibility(private).returns(Integer) { ... }
y = def (a, b) { ... }
y.visibilityprivate) # apply annotations later
y.returnsinteger)
where for anonation examples:
class Method
def visibility(v)
@annotations[:visibility] = v
return self
end
def returns(r)
@annotations[:returns] = v
return self
end
end
Please rake me over the coals because I am so ignorant ;-)
Steve Tuckner