Thread overview
ternary op assign
May 02
monkyyy
May 02
monkyyy
3 days ago
Quirin Schroll
3 days ago
monkyyy
May 02

foo?=bar:baz is rewritten as foo.opOpAssign!("?:")(bar,baz)

foo[i]?=bar:baz opIndexOpAssign

for basic types it acts as foo=(bool)bar?foo:(typeof(foo))baz

May 02

On Thursday, 2 May 2024 at 17:42:28 UTC, monkyyy wrote:

>

foo?=bar:baz is rewritten as foo.opOpAssign!("?:")(bar,baz)

foo[i]?=bar:baz opIndexOpAssign

for basic types it acts as foo=(bool)bar?foo:(typeof(foo))baz

I find this syntax confusing, I would interpret that as:

foo[i] = (foo[i] ? bar : baz);

May 02

On Thursday, 2 May 2024 at 18:17:12 UTC, Stefan Koch wrote:

>

On Thursday, 2 May 2024 at 17:42:28 UTC, monkyyy wrote:

>

foo?=bar:baz is rewritten as foo.opOpAssign!("?:")(bar,baz)

foo[i]?=bar:baz opIndexOpAssign

for basic types it acts as foo=(bool)bar?foo:(typeof(foo))baz

I find this syntax confusing, I would interpret that as:

foo[i] = (foo[i] ? bar : baz);

often the statement you want to write is a=condition?b:a which repeats a, the way to simplify (and prevent int promtion issues) is with the += family of statements; but there isnt a clear one for if(cond)a=b

Simd(/waterfalled code) has to do bit mask tricks, and I think you could wrap that up in a data structure with the opslice as recursive templates for opindex logic

a/=4;
b+=a;
if(a>b)a=b;
---
a[0..4]/=4;
b[0..4]+=a[0..4];
????
3 days ago

On Thursday, 2 May 2024 at 17:42:28 UTC, monkyyy wrote:

>

foo?=bar:baz is rewritten as foo.opOpAssign!("?:")(bar,baz)

foo[i]?=bar:baz opIndexOpAssign

for basic types it acts as foo=(bool)bar?foo:(typeof(foo))baz

Isn’t this just if (!bar) foo = baz;?

Where would the user-defined operator be useful?

3 days ago

On Thursday, 16 May 2024 at 16:57:17 UTC, Quirin Schroll wrote:

>

On Thursday, 2 May 2024 at 17:42:28 UTC, monkyyy wrote:

>

foo?=bar:baz is rewritten as foo.opOpAssign!("?:")(bar,baz)

foo[i]?=bar:baz opIndexOpAssign

for basic types it acts as foo=(bool)bar?foo:(typeof(foo))baz

Isn’t this just if (!bar) foo = baz;?

Where would the user-defined operator be useful?

when bar depends on foo; such as a user defined cond, lets saya database query that takes in lamdas

foo?=a=>a%2:baz

and when its "multiable data single instruction", simd or parrellizism, ranges etc. and theres something in that index
you can not write if(!bar[foo's slice????]) foo=baz[...];