Ok, I have machiavellian reason for asking for this,
but I think
it may be generally handy...
How about extending the function invocation operations
to include
co-expressions as well as functions and integers? That
is, given
co-expression C:
C()
C(3)
would be equivalent to:
@C
3@C
the only real issue is what to do with:
C(3,4)
but that can be handled a number of ways.
That way, a Unicon solution to the challenge at:
http://www.paulgraham.com/accgen.html
would simply be:
procedure accgen(n)
c := create while i := n@&source do n +:= i
return (@c,c)
end
And the use would be:
C := accgen(1)
write(C(5))
D := accgen(3)
D(5)
write(C(2.3))
Note that without some sort of extension to function
invocation,
(operator overloading would work) the challenge is not
doable in
Unicon...
Steve Wampler
2005-07-19
Logged In: YES
user_id=74070
Incidently, what's *really* being asked for here is a way to
make 'closures' semi-first class entities in Unicon. A
co-expression
provides most of an implementation for a closure. Having this
'closure' look like a function is all that's missing from this
particular implementation.
Steve Wampler
2008-07-02
Logged In: YES
user_id=74070
Originator: YES
I'd like to amend this (making it even easier to implement!).
The syntax should treat: C(3)
as equivalent to: [3]@C instead of the earlier proposal of: 3@C
That allows: C(1,2,3) to fall out as [1,2,3]@C.
So the basic Unicon invocation method could simply test for LHS as a co-expression
should the tests for procedure, method, function, and integer all fail. (Presumably
this is really a switch statement, and no less efficient.)