Live data from Hacker News

Weird Lexical Syntax

justine.lol

231–234 of 234 posts

Re: Weird Lexical Syntax

#231
post #227
post #225

Earlier quoted context omitted.

> $ /usr/bin/ruby -e 'puts % hello + "world"' Yes, it's roughly limited in use to places where it is not ambiguous whether it would be the start of a quoted string or the modulus operator, and after a method name would be ambiguous. > but, at the intersection is "ruby parsing is the 15th circle of hell" It's surprisingly (not this part, anyway) not that hard. You "just" need to create a forward reference, and keep tr…

How are you so awesome?

Thanks. I'm a big fan of your work, so that is appreciated...

Re: Weird Lexical Syntax

#232
post #22

Some random things that the author seem to have missed: > but TypeScript, Swift, Kotlin, and Scala take string interpolation to the furthest extreme of encouraging actual code being embedded inside strings Many more languages support that: C# $"{x} plus {y} equals {x + y}" Python f"{x} plus {y} equals {x + y}" JavaScript `${x} plus ${y} equals ${x + y}` Ruby "#{x} plus #{y} equals #{x + y}" Shell "$x plus $y equals $…

Shell "$x plus $y equals $((x+y))" Shell "$x plus $y equals $((expr $x + $y))"

Correction: Shell "$x plus $y equals $(expr $x + $y)"

Re: Weird Lexical Syntax

#233
post #22

Some random things that the author seem to have missed: > but TypeScript, Swift, Kotlin, and Scala take string interpolation to the furthest extreme of encouraging actual code being embedded inside strings Many more languages support that: C# $"{x} plus {y} equals {x + y}" Python f"{x} plus {y} equals {x + y}" JavaScript `${x} plus ${y} equals ${x + y}` Ruby "#{x} plus #{y} equals #{x + y}" Shell "$x plus $y equals $…

One cool feature of C# interpolated strings is that they are lazy. Many loggers used to implement their own interpolation because something like

    log.trace($"Entering iteration {i} for customer {c.ID} [{c.ShortName}]");
in a hot loop would call string.Concat every time it was called before the logger could bail out of the method.

C# lets you declare an overload that accepts a `DefaultInterpolatedStringHandler` (or your own custom implementation of the handler pattern) and this overload will take precedence and allow you to delay the building of the string until after you've checked whether logging it is required.

Re: Weird Lexical Syntax

#234
post #53

I think my favorite C trigraph was something like do_action() ??!??! handle_error() It almost looks like special error handling syntax but still remains satisfying once you realize it's an || logical-or statement and it's using short circuiting rules to execute handle error if the action returns a non-zero value.

Did you choose the legacy C trigraphs over || for aesthetic purposes?

No, I don't really write C. I was remarking on something I saw once and I wanted to share it because the original article mentions trigraphs.
Post reply on HN