Is a single value variable also a tuple?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Is a single value variable also a tuple?

Boon Chew

Is a single value variable also a tuple? Given that tuple is a type, how can the variable below be both an Int and a tuple?

var value:Int = 123 // or (123)
print(value.0)  // this works


--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3168db4e-c813-4997-bf3c-97500b0ee680%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Is a single value variable also a tuple?

Jens Alfke

On Jul 9, 2015, at 8:45 AM, Boon <[hidden email]> wrote:

Is a single value variable also a tuple? Given that tuple is a type, how can the variable below be both an Int and a tuple?

IIRC a 1-tuple is equivalent to the value it contains; in other words the compiler ignores the parens when there’s only one value inside.

—Jens

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/F3AEA461-21DC-462F-9624-E95021A5F7F6%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Is a single value variable also a tuple?

Boon Chew
Understand this - question is is the variable technically still a tuple? reflect() doesn't say so even though you can do this:

let x = 100
print(x.0)

On Thursday, July 9, 2015 at 1:00:00 PM UTC-4, Jens Alfke wrote:

On Jul 9, 2015, at 8:45 AM, Boon <<a href="javascript:" target="_blank" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">bo...@...> wrote:

Is a single value variable also a tuple? Given that tuple is a type, how can the variable below be both an Int and a tuple?

IIRC a 1-tuple is equivalent to the value it contains; in other words the compiler ignores the parens when there’s only one value inside.

—Jens

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/4b671f9b-d358-43ea-b1e3-fcd413799dc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Is a single value variable also a tuple?

lowell!

> On Jul 9, 2015, at 2:39 PM, Boon <[hidden email]> wrote:
>
> Understand this - question is is the variable technically still a tuple?

No. From the language reference:

>  If there is only one element inside the parentheses, the type is simply the type of that element. For example, the type of (Int) is Int, not (Int).

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-ID448

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/5705578E-96E4-4BB3-B00D-B8EB2AA730AB%40me.com.
For more options, visit https://groups.google.com/d/optout.

smime.p7s (6K) Download Attachment