<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Oct 4, 2017, at 6:41 AM, Alex Blewitt via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div><blockquote type="cite" class=""><div class="">On 4 Oct 2017, at 11:42, Mike Kluev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span style="font-size:12.800000190734863px" class="">on Tue, 3 Oct 2017 11:00:33 -0600 </span><span style="font-size:12.800000190734863px" class="">Dave DeLong <</span><a href="mailto:swift@davedelong.com" style="font-size:12.800000190734863px" class="">swift@davedelong.com</a><span style="font-size:12.800000190734863px" class="">></span><br style="font-size:12.800000190734863px" class=""> wrote:<div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><span style="font-size:12.800000190734863px" class="">> Because, ideally, I’d love to be able to do:</span><br style="font-size:12.800000190734863px" class="">> <br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">> infix operator and: LogicalConjunctionPrecedence // or whatever the precedence is called</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">> func and(lhs: Bool, rhs: Bool) → Bool { return lhs && rhs }</span><br style="font-size:12.800000190734863px" class="">> <br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">> let truthyValue = true and false</span><div class="gmail_extra"><br class=""></div><div class="gmail_extra">+1 (i like your thinking, even if it is unlikely to happen in swift)</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">(noteworthy, your example used "RIGHTWARDS ARROW" (U+2192) instead of ->, whether on purpose or not.)</div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>Heh, right. That was unintentional. I have system text replacements set up to turn ->, =>, <->, etc in to their Unicode arrow versions: →, ⇒, ↔︎ </div><div><br></div><div>And using words (and even phrases like “is not”) as operators is totally possible. It would just require the parser to have a known list of all operators, and then greedily match characters as long as there’s an operator that’s prefixed by the current token, and then backtrack when it fails. </div><div><br></div><div>I implemented this style of operator definition and parsing in my open source math parsing library: <a href="https://github.com/davedelong/DDMathParser">https://github.com/davedelong/DDMathParser</a> </div><div><br></div><div>Dave</div><br><blockquote type="cite"><div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""></div><div class="gmail_extra">speaking of &&, was it just a copy-paste from C or is there a more fundamental reason to use that instead of &? in C they had to use two different operators because of the implicit int <-> bool promotions, but in swift "true & false" vs "1 & 2" would have been distinguishable.</div></div></div></blockquote><br class=""></div><div>The difference between the & and && operators isn't to do with the implicit conversions; it's to do with whether both sides of the expression are evaluated or not.</div><div><br class=""></div><div>false && system('rm -rf')</div><div><br class=""></div><div>You really don't want to do that if both sides are executed ...</div><div><br class=""></div><div>Alex</div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>