Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#32 co-expr activation via function invocation syntax

open
nobody
None
5
2005-07-19
2005-07-19
Steve Wampler
No

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...

Discussion

  • Steve Wampler
    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
    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.)