Re: [csswg-drafts] [css-values] Iverson bracket functions (#4731)

> I propose three mathematical functions inspired by Iverson bracket notation — if(p), media(q), supports(s)

If we want boolean functions, I think it may be clearer if we consider a new type

```
<bool> = true | false
```

This wouldn't be a numeric value (I guess it could be a CSSKeywordValue, but I don't know much about Typed OM), so things like `<bool> + <bool>` or `min(<bool>, <bool>)` wouldn't be valid.

A `media(q)` or `supports(s)` would have type `<bool>`.

Operators like `<`, `!=`, `&&` would attempt to add the types of the left and right arguments. If this returns failure, the entire calculation’s type would be failure. Otherwise, the returned type would be `<bool>`

Then, `if(<bool>, then?, else?)` would attempt to add the types of the `then` and `else` arguments. If this returns failure, the entire calculation’s type would be failure. Otherwise, the sub-expression’s type would be the returned type. If omitted, `then` would default to `1`, and `else` would default to a numeric value 0 with the same type as `then`.

So your example would become

```css
:root {
  --dur: if(media(prefers-reduced-motion), 5s);
}
```

This makes it more clear that we want to set `5s` conditionally, not set some random multiple of `5s`.

Probably, `if(<bool>, then, else)` should also accept `then` and `else` to be `<bool>`, and then return `<bool>`:

```css
if(if(A > B, C > D, E > F), 10px, 20px);
/* same as */
if((A > B && C > D) || (!(A > B) && E > F), 10px, 20px);
```


-- 
GitHub Notification of comment by Loirooriol
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4731#issuecomment-582081510 using your GitHub account

Received on Tuesday, 4 February 2020 19:43:03 UTC