<div dir="ltr"><div><br></div>Oops. Kindly disregard my previous emails. Ben was kind enough to point out to me that I was confusing dictionary literals with DictionaryLiteral<div><br><div class="gmail_quote">On Tue, Jan 9, 2018 at 8:56 PM, Ben Cohen <span dir="ltr">&lt;&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div></div><div>Hi Charles,</div><div><br></div><div>The naming issue strikes again :)</div><div><br></div><div>Your code is making use of dictionary literals, not DictionaryLiteral. We are talking about the (clearly confusingly named!) DictionaryLiteral type, which is a type you can create from a dictionary literal. (See docs here: <a href="https://developer.apple.com/documentation/swift/dictionaryliteral" target="_blank">https://developer.apple.<wbr>com/documentation/swift/<wbr>dictionaryliteral</a>)</div><div><br></div><div>There’s no suggestion of getting rid of the ExpressibleByDictionaryLiteral capability. </div><div><br></div><div>“Ceci n’est pas une literal”</div><div> - Magritte</div><div><br>On Jan 9, 2018, at 8:26 PM, Charles Constant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div dir="ltr">Hi Nevin (et al) <div><br></div><div>Here&#39;s the relevant section of my code. It&#39;s from a protocol I use called &quot;ParameterSet&quot; to extend OptionSets to contain small numbers (like an Enum with an associated type, but all the data is stored in the UInt). Wouldn&#39;t be my first choice to share, as it breaks KISS. Anyhow, the &quot;<wbr>ExpressibleByDictionaryLiteral<wbr>&quot; lets me specify a &quot;params&quot; template tersely. I only found out how to use the -Literal initializers last year. I love them.</div><div><div><br></div><div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>struct DrumNote: ParameterSet {</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>let rawValue: UInt</div><div><br></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>static let params: [ParamType] = [ [&quot;velocity&quot;:0...255], &quot;flam&quot;, &quot;roll&quot;, &quot;reverse&quot; ]</div><div><br></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>static let</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>velocity<span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>= param(0),</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>flam<span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>= param(1),</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>roll<span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>= param(2),</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>reverse<span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>= param(3),</div><div><br></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>// ...</div><div><br></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>}</div><div><br></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>enum ParamType: ExpressibleByStringLiteral, ExpressibleByDictionaryLiteral {</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>public init( dictionaryLiteral elements: (String,Any)... ) {</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>if let pair = elements.first as? (String,ClosedRange&lt;<wbr>FloatLiteralType&gt;) { self = .doub(pair.0,pair.1) }</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>else if let pair = elements.first as? (String,CountableClosedRange&lt;<wbr>IntegerLiteralType&gt;) { self = .int(pair.0, pair.1.lowerBound ... pair.1.upperBound ) }</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>else { fatalError(&quot;Can only init from Double...Double or Int...Int&quot;) }</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>}</div><div><br></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>// ...</div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span></div><div><span class="gmail-m_4449909344175415166gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>}</div></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 9, 2018 at 6:10 PM, Nevin Brackett-Rozinsky <span dir="ltr">&lt;<a href="mailto:nevin.brackettrozinsky@gmail.com" target="_blank">nevin.brackettrozinsky@gmail.<wbr>com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 9, 2018 at 7:47 PM, <a href="mailto:charles@charlesism.com" target="_blank">charles@charlesism.com</a> <span dir="ltr">&lt;<a href="mailto:charlesism.com@gmail.com" target="_blank">charlesism.com@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto">I used a DictionaryLiteral only yesterday, and it turned what would have a typically unreadable array of Structs into something much more elegant. I&#39;m pretty sure the only reason Literals (of all varieties) aren&#39;t used more often is because Swift programmers don&#39;t realize they are available and easy to implement. <br></div></blockquote><div><br></div><div>Could you provide an example of how you used DictionaryLiteral?</div><span class="gmail-m_4449909344175415166gmail-HOEnZb"><font color="#888888"><div><br></div><div>Nevin </div></font></span></div></div></div></blockquote></div><br></div></div></div></blockquote><blockquote type="cite">______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></blockquote><div><br></div></div></blockquote></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 9, 2018 at 8:26 PM, Charles Constant via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Nevin (et al) <div><br></div><div>Here&#39;s the relevant section of my code. It&#39;s from a protocol I use called &quot;ParameterSet&quot; to extend OptionSets to contain small numbers (like an Enum with an associated type, but all the data is stored in the UInt). Wouldn&#39;t be my first choice to share, as it breaks KISS. Anyhow, the &quot;<wbr>ExpressibleByDictionaryLiteral<wbr>&quot; lets me specify a &quot;params&quot; template tersely. I only found out how to use the -Literal initializers last year. I love them.</div><div><div><br></div><div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>struct DrumNote: ParameterSet {</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>let rawValue: UInt</div><div><br></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>static let params: [ParamType] = [ [&quot;velocity&quot;:0...255], &quot;flam&quot;, &quot;roll&quot;, &quot;reverse&quot; ]</div><div><br></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>static let</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>velocity<span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>= param(0),</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>flam<span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>= param(1),</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>roll<span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>= param(2),</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>reverse<span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>= param(3),</div><div><br></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>// ...</div><div><br></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>}</div><div><br></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>enum ParamType: ExpressibleByStringLiteral, ExpressibleByDictionaryLiteral {</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>public init( dictionaryLiteral elements: (String,Any)... ) {</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>if let pair = elements.first as? (String,ClosedRange&lt;<wbr>FloatLiteralType&gt;) { self = .doub(pair.0,pair.1) }</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>else if let pair = elements.first as? (String,CountableClosedRange&lt;<wbr>IntegerLiteralType&gt;) { self = .int(pair.0, pair.1.lowerBound ... pair.1.upperBound ) }</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                                </span>else { fatalError(&quot;Can only init from Double...Double or Int...Int&quot;) }</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>}</div><div><br></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>// ...</div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span></div><div><span class="gmail-m_6763855055537614895gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>}</div></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 9, 2018 at 6:10 PM, Nevin Brackett-Rozinsky <span dir="ltr">&lt;<a href="mailto:nevin.brackettrozinsky@gmail.com" target="_blank">nevin.brackettrozinsky@gmail.<wbr>com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 9, 2018 at 7:47 PM, <a href="mailto:charles@charlesism.com" target="_blank">charles@charlesism.com</a> <span dir="ltr">&lt;<a href="mailto:charlesism.com@gmail.com" target="_blank">charlesism.com@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>I used a DictionaryLiteral only yesterday, and it turned what would have a typically unreadable array of Structs into something much more elegant. I&#39;m pretty sure the only reason Literals (of all varieties) aren&#39;t used more often is because Swift programmers don&#39;t realize they are available and easy to implement. <br></div></div></blockquote><div><br></div><div>Could you provide an example of how you used DictionaryLiteral?</div><span class="gmail-m_6763855055537614895gmail-HOEnZb"><font color="#888888"><div><br></div><div>Nevin </div></font></span></div></div></div>
</blockquote></div><br></div></div></div>
<br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>