[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-dev
Subject:    Re: [groovy-dev] The opposite of builders
From:       John Rose <rose00 () mac ! com>
Date:       2005-01-29 9:28:31
Message-ID: 23CBD44A-71D8-11D9-9EAE-000D93505406 () mac ! com
[Download RAW message or body]

On Jan 29, 2005, at 0:21, jstrachan wrote:
>> For example, a straw man syntax:
>>    switch (x)  { case foo(def x, def y): println x }
>
> I don't quite follow what this means; x is switched on, then passed 
> into foo(), but z is printed? And what is the value of y?

Sorry, garbled example; I meant xyz instead of xxy.  Should be:
    switch (x)  { case foo(def y, def z): println z }

Means:  Take x, see if it is the result of a 2-argument foo call.
If so, deduce those two arguments, and print the second of them.

How does one deduce whether something is of the form foo(x, y)?
You obviously can't in general, but some languages (like ML)
allow you to define specially-marked functions which are reversible in 
this way.
The compiler recognizes them in ML; in Groovy I assume they would be 
dynamically recognized.

This obviously has the potential to jibe with Groovyified 
keyword-driven Java constructors.
   switch (x) { case Complex(re: def x:, im: def y): println "$x+${y}i" }

(This needs lots of tweaking though.  The re vs. x distinction would be 
annoying, and maybe there's a better way to mark free variables than 
'def'.)

-- John


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic