static arrays becoming value types

Leandro Lucarella llucax at gmail.com
Wed Oct 21 11:14:16 PDT 2009


language_fan, el 21 de octubre a las 17:52 me escribiste:
> Wed, 21 Oct 2009 16:54:22 +0000, language_fan thusly wrote:
> 
> > Wed, 21 Oct 2009 10:48:34 -0500, Andrei Alexandrescu thusly wrote:
> > 
> >> language_fan wrote:
> >>> Wed, 21 Oct 2009 11:07:29 -0400, Robert Jacques thusly wrote:
> >>>> My issue was that all your example _showed_ was nominal typing.
> >>>> Though I didn't mention it by name, I did mention that if SOL tuples
> >>>> had structural typing, it might would be a different story. (Well,
> >>>> until/if opImplicitCast was implemented, as it would allow for
> >>>> structural typing.)
> >>> 
> >>> Why do you insist on using nominal typing for tuples and the library
> >>> defined "literal". If I want plain old tuples without any kind of type
> >>> name, why should I care about extra hand waving needed to make it
> >>> work.
> >> 
> >> I'm late in this dialog, but I'm not seeing an impediment here. What
> >> does it matter to you that tuples actually have a name vs. not having a
> >> name at all?
> > 
> > Using tuples in D is a major pain in the ass. In fact it has been made
> > so hard that people start avoiding the feature like plague. I wrote some
> > test code to reveal how inconsistent their semantics are. Note that you
> > need the built-in tuples for some stuff, like assigning and mixed value/
> > type tuples. Stuples can only be used as values and when the auto-
> > flattening is not desired.
> > 
> >>>> STARTS HERE
> 
> Even though not being an expert in Python (have not really used it), as 
> an experiment I managed to successfully port the examples in 2 minutes 
> without any kind of problems.

I think this is an important point too. Maybe tuples are not *that* broken
as stated in this thread, but they are quite more complex to understand
than tuples in other languages, and they feel somehow hackish.

> a = (1,1)
> e1 = a[0]
> 
> print a
> 
> def retTest():
>   return (1,1)
> 
> (d,e) = (10,20)
> 
> (d,_) = (10,20)
> 
> (d,b) = (1, retTest())
> 
> a3b = [ (1,1), (2,2) ]
> 
> a7 = { (1,1) : 5 }
> 
> a8 = { 5 : (1,1)}

In python you can even do:

def f(a, b, c):
	print a, b, c

x = (b, c)
f(a, *x) # calls to f(a, b, c)

I think this is only possible in D with type tuples, not with ... "value
tuples"? That's part of the complexity, having 2 type of tuples is very
confusing.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
You are the very reason why everything happens to you



More information about the Digitalmars-d mailing list