[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strange Operators (Was: Why I leave Lua)
- From: William Ahern <william@...>
- Date: Wed, 9 Jul 2014 23:05:03 -0700
On Wed, Jul 09, 2014 at 05:09:42PM -0700, Coroutines wrote:
> On Wed, Jul 9, 2014 at 5:05 PM, Coroutines <coroutines@gmail.com> wrote:
>
> > The spaceship operator is my favorite ("<=>"):
> > https://en.wikipedia.org/wiki/Spaceship_operator
>
> Another fun one is the NULL coalescing operator found in some languages.
>
> In Lua you handle default args like:
>
> if default_arg then
> default_arg = 3
> end
>
> -- or
>
> default_arg = default_arg or 3
>
> (let's pretend I'm comparing against nil for best practices)
>
> Anyway, C# has "??" to do that: default_arg = default_arg ?? 3;
>
> https://en.wikipedia.org/wiki/Null_coalescing_operator
GCC C has ?:
z = x?:y;
It's just a hack on the ternary operator, but behaves precisely the same way
in that x will only be evaluated once. GCC has supported this since at least
2.95, circa 1999.