crazy tuple ideas.
Daniel Keep
daniel.keep.lists at gmail.com
Mon Mar 5 19:31:09 PST 2007
Russell Lewis wrote:
> Daniel Keep wrote:
>>
>> +1 on nested tuples, although the symbols appearing unquoted is somewhat
>> iffy.
>
> I agree that nested tuples would be cool, though I'm not 100% sure what
> the syntax should be. Perhaps the existing syntax (where tuples are
> unrolled by default) needs to be made more explicit.
>
> However, you can already roll your own nested tuples, at least for some
> things. You can take a type-tuple and create a struct:
> struct TupleBoxer {
> MyTuple elements;
> }
> and although I haven't written one, yet, I bet that you could write a
> template which would do the same with expression-tuples. Note that you
> can encapsulate an expression in a struct like this:
> struct ExpressionBoxer {
> static const uint foo = <myExpression>;
> }
> and so you should be able to write a template which takes an
> expression-tuple and builds a struct like that for you. Perhaps type
> deduction makes this really easy?
>
> I'm not saying that any of this is as good as nested Tuples, but it's a
> start.
Well, for reference, Python "explodes" tuples using what is essentially
C's dereference syntax.
>>> def print_words(word1, word2):
print word1, word2
>>> words = ("Hello", "World!")
>>> print_words(*words)
Hello World!
Incidentally, this also works...
>>> words = {"word1":"Hello", "word2":"World!"}
>>> print_words(**words)
Hello World!
As does this :P
>>> pos_args = ("Hello",)
>>> named_args = {"word2":"World!"}
>>> print_words(*pos_args, **named_args)
Hello World!
-- Daniel
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list