<div dir="ltr"><p>That’s how the Swift interpreter prints out closures. Try <code>let testClosure = {}</code> in the REPL and you’ll get a similar result, except with different arguments and return value due to <code>{}</code> being <code>() -> ()</code>.</p>
<br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 15, 2016 at 8:13 PM Doug Hill via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Thank you Saagar for looking over this code for me. I guess I got really caught up in the weird diagnostic message and assumed things weren’t working.<div>Now I see that ‘afunc’ works as I expected:</div><div><br></div><div><div><font face="Menlo" style="font-size:12px">60> g.afunc(numberRecords:1,userRecord:(13,9))</font></div><div><font face="Menlo" style="font-size:12px">13 9</font></div><div><font face="Menlo" style="font-size:12px">$R3: (Int, (Int, Int)) = {</font></div><div><font face="Menlo" style="font-size:12px"> 0 = 13</font></div><div><font face="Menlo" style="font-size:12px"> 1 = {</font></div><div><font face="Menlo" style="font-size:12px"> 0 = 9</font></div><div><font face="Menlo" style="font-size:12px"> 1 = 1</font></div><div><font face="Menlo" style="font-size:12px"> }</font></div><div><font face="Menlo" style="font-size:12px">}</font></div></div><div><br></div><div>Although I would be interested in why the compiler spits out the first message in the first place (e.g. the message with the strange description of afunc).</div><div><br></div><div>Looking forward to see what I can do with Swift,</div><div><br></div><div>Doug Hill</div></div><div style="word-wrap:break-word"><div><br><div><blockquote type="cite"><div>On Jun 15, 2016, at 6:49 PM, Saagar Jha <<a href="mailto:saagarjha28@gmail.com" target="_blank">saagarjha28@gmail.com</a>> wrote:</div><br><div><div dir="ltr">`Gen` defines `afunc`, but you’re trying to access `aFunc`.<br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 15, 2016 at 6:22 PM Doug Hill via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I’m just starting to learn Swift and attempting to do some functional-style programming. Specifically I’m learning how to create generic algorithms that can be reused for many different types.</div><div>What I’m attempting to do is create a new object, passing functions to the initializer. The class would store these functions as properties and then use them for functional-style algorithms.<div><br></div><div>The problem is I’m running into weird compiler errors/messages that I’m trying to figure out. I'm hoping someone here can give me some pointers on what these errors mean, and most likely what I’m doing wrong.</div><div><br></div></div><div><span style="white-space:pre-wrap">        </span> <font face="Menlo" style="font-size:12px">Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31) Target: x86_64-apple-macosx10.9</font></div><div><font face="Menlo" style="font-size:12px"><br></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="Menlo" style="font-size:12px">// =====================================================================</font></div></div><div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span style="color:rgb(187,44,162)">class</span><span> Gen<InputKeyType, InputValueType, OutputKeyType, OutputValueType> </span></span><span style="font-size:12px">{</span></div></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(187,44,162)">typealias</span><span> func1Type = (numberRecords:</span><span style="color:rgb(79,129,135)">InputKeyType</span><span>, userRecord: </span><span style="color:rgb(79,129,135)">InputValueType</span><span> ) -> (</span><span style="color:rgb(79,129,135)">OutputKeyType</span><span>, </span><span style="color:rgb(79,129,135)">OutputValueType</span><span>)</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px"><span style="font-size:12px"><br></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(187,44,162)">var</span><span> afunc: </span><span style="color:rgb(79,129,135)">func1Type</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px"><span style="font-size:12px"><br></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(187,44,162)">init</span><span>( inFunc: </span><span style="color:rgb(79,129,135)">func1Type</span><span> ) </span></span><span style="font-size:12px">{</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(79,129,135)">afunc</span><span> = inFunc</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"> }</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px">}</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px"><span style="font-size:12px"><br></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span style="color:rgb(187,44,162)">var</span><span> g: </span><span style="color:rgb(79,129,135)">Gen</span><span><</span><span style="color:rgb(112,61,170)">Int</span><span>, (</span><span style="color:rgb(112,61,170)">Int</span><span>, </span><span style="color:rgb(112,61,170)">Int</span><span>), </span><span style="color:rgb(112,61,170)">Int</span><span>, (</span><span style="color:rgb(112,61,170)">Int</span><span>, </span><span style="color:rgb(112,61,170)">Int</span><span>)> =</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"> Gen</span><span style="font-size:12px">( inFunc: </span><span style="font-size:12px">{ </span><span style="font-size:12px">(numberRecords: </span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, userRecord: (</span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, </span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">)) </span><span style="font-size:12px">-> (</span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, (</span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, </span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">)) </span><span style="font-size:12px;color:rgb(187,44,162)">in</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(187,44,162)">var</span><span> b: </span><span style="color:rgb(112,61,170)">Int</span><span> = numberRecords</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(187,44,162)">var</span><span> (age, numFriends) = userRecord</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(61,29,129)">print</span><span>( (age), (numFriends) )</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span> </span><span style="color:rgb(187,44,162)">return</span><span> (age, (numFriends, </span><span style="color:rgb(39,42,216)">1</span><span>))</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"> }</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"> )</span></div></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><div style="font-family:Helvetica;font-size:14px">// =====================================================================</div></span></div></blockquote><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><div style="font-family:Helvetica;font-size:14px"></div></span></div><div style="margin:0px;line-height:normal"><font face="HelveticaNeue"><br></font></div><div style="margin:0px;line-height:normal"><font face="HelveticaNeue">What I get as output from the Swift compiler are these confusing messages. I included some print statements that hopefully gives some more info about what’s happening.</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><br></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">g: Gen<Int, (Int, Int), Int, (Int, Int)> = {</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px"> afunc = 0x00000001012024d0 $__lldb_expr7`partial apply forwarder for reabstraction thunk helper from @callee_owned (@unowned Swift.Int, @unowned Swift.Int, @unowned Swift.Int) -> (@unowned (Swift.Int, (Swift.Int, Swift.Int))) to @callee_owned (@in Swift.Int, @in (Swift.Int, Swift.Int)) -> (@out (Swift.Int, (Swift.Int, Swift.Int))) at repl6.swift</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">}</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px"><br></span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">print( (g) )</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">Gen<Swift.Int, (Swift.Int, Swift.Int), Swift.Int, (Swift.Int, Swift.Int)></span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px"><br></span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">print( (g.aFunc) )</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">repl.swift:48:9: error: value of type 'Gen<Int, (Int, Int), Int, (Int, Int)>' has no member 'aFunc'</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><span style="font-size:12px;font-family:Menlo"> ^ ~~~~~</span></div></div></blockquote><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">There’s a good chance I’m doing something wrong but I don’t know how to figure out what that problem is. Any ideas?</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">Thanks.</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">Doug</div></div></div>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div>
</div></blockquote></div><br></div></div>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div>