[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Destructuring lambdas in T?



        Is there any destructuring lambda in T (or a clean way to simulate one)?
    
    Why not hide define-destructure in a macro?
    
        (define-with-pattern (foo (x y) z) ...)
        => (define (foo . <generated-symbol>)
            (destructure ((((x y) z) <generated-symbol>)) ...)
    
    The unclean part is that the body of foo is in the scope of the generated
    symbol but that should never have any practical consequence.
    -------
    
The major problem with this is that:

        (foo '(a b) 'c)
and     (foo '(a b) 'c 'extra-argument)

both return (a b c), whereas:

        (foo '(a b))   ; missing argument.

returns (a b ()).  One would need to generate-symbol a symbol for each of
foo's arguments, and destructure each of them individually.

The minor problem is that foo now looks ugly (try pretty-printing it.)  Isn't
there a way to define-compilator a new lambda-form, say dlambda (for
destructuring lambda), so that the transformation is completely transparent?

Also, is there some reason why lambda doesn't destructure its arguments anyway
(except for the ". x" tail form)?  A form like

        (lambda ((x y) z) ...)

simply ignores the (x y) argument position.  It would be trivial to compile
old-style lambdas into non-destructuring code so you wouldn't lose out on
efficiency, but you would gain in generality and expressive power if you needed
it.  This way one lambda form would do it all.

Ashwin.


-------