<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>print &#8211; Wade Tregaskis</title>
	<atom:link href="https://wadetregaskis.com/tags/print/feed/" rel="self" type="application/rss+xml" />
	<link>https://wadetregaskis.com</link>
	<description></description>
	<lastBuildDate>Mon, 26 Feb 2024 01:19:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wadetregaskis.com/wp-content/uploads/2016/03/Stitch-512x512-1-256x256.png</url>
	<title>print &#8211; Wade Tregaskis</title>
	<link>https://wadetregaskis.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">226351702</site>	<item>
		<title>Swift `print` takes multiple arguments</title>
		<link>https://wadetregaskis.com/swift-print-takes-multiple-arguments/</link>
					<comments>https://wadetregaskis.com/swift-print-takes-multiple-arguments/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Mon, 26 Feb 2024 17:00:00 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://wadetregaskis.com/?p=7787</guid>

					<description><![CDATA[I forget this too often, and write things like: Sometimes I feel like I&#8217;m really just writing stress-tests for the Swift syntax parser. The above can actually be written a bit more simply, as: Not just fewer characters, but conceptually simpler &#8211; fewer nested parenthesis, and no nested string literals at all. See, print&#8216;s function&#8230; <a class="read-more-link" href="https://wadetregaskis.com/swift-print-takes-multiple-arguments/" data-wpel-link="internal">Read more</a>]]></description>
										<content:encoded><![CDATA[
<p>I forget this too often, and write things like:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled" data-code-block-pro-font-family="" style="font-size:.875rem;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #795E26">print</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;Size: </span><span style="color: #EE0000">\(</span><span style="color: #A31515">thingy.getSize(&quot;</span><span style="color: #001080">Example</span><span style="color: #A31515">&quot;))&quot;</span><span style="color: #000000">)</span></span></code></pre></div>



<p>Sometimes I feel like I&#8217;m really just writing stress-tests for the Swift syntax parser.</p>



<p>The above can actually be written a bit more simply, as:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled" data-code-block-pro-font-family="" style="font-size:.875rem;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #795E26">print</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;Size:&quot;</span><span style="color: #000000">, </span><span style="color: #001080">thingy</span><span style="color: #000000">.</span><span style="color: #795E26">getSize</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;Example&quot;</span><span style="color: #000000">))</span></span></code></pre></div>



<p>Not just fewer characters, but conceptually simpler &#8211; fewer nested parenthesis, and no nested string literals at all.</p>



<p>See, <code>print</code>&#8216;s function signature is not in fact merely <code>print(_ s: String)</code>, but:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled" data-code-block-pro-font-family="" style="font-size:.875rem;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #001080">func</span><span style="color: #000000"> </span><span style="color: #795E26">print</span><span style="color: #000000">&lt;</span><span style="color: #267F99">Target</span><span style="color: #000000">&gt;(</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #001080">_</span><span style="color: #000000"> </span><span style="color: #001080">items</span><span style="color: #000000">: </span><span style="color: #001080">Any</span><span style="color: #000000">...,</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #001080">separator</span><span style="color: #000000">: </span><span style="color: #001080">String</span><span style="color: #000000"> = </span><span style="color: #A31515">&quot; &quot;</span><span style="color: #000000">,</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #001080">terminator</span><span style="color: #000000">: </span><span style="color: #001080">String</span><span style="color: #000000"> = </span><span style="color: #A31515">&quot;</span><span style="color: #EE0000">\n</span><span style="color: #A31515">&quot;</span><span style="color: #000000">,</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #001080">to</span><span style="color: #000000"> </span><span style="color: #001080">output</span><span style="color: #000000">: </span><span style="color: #001080">inout</span><span style="color: #000000"> </span><span style="color: #001080">Target</span></span>
<span class="line"><span style="color: #000000">) </span><span style="color: #001080">where</span><span style="color: #000000"> Target : </span><span style="color: #001080">TextOutputStream</span></span></code></pre></div>



<p>(I&#8217;m ignoring the specialisation that omits the <code>to</code> parameter &#8211; conceptually there&#8217;s just one <code>print</code> function)</p>



<p>It&#8217;s a pity that Swift still doesn&#8217;t have <a href="https://forums.swift.org/t/explicit-array-splat-for-variadic-functions/11326" data-wpel-link="external" target="_blank" rel="external noopener">splatting</a>, as that&#8217;d enable a nicer way of printing collections, than having to use <code>.joined(by: …)</code>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wadetregaskis.com/swift-print-takes-multiple-arguments/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7787</post-id>	</item>
	</channel>
</rss>
