Re: [csswg-drafts] [css-mixins] custom mixins & functions should have some access to custom properties on the calling element. How much? (#9938)

I think functions and mixins are very different regarding whether/how to access external variables, and should be discussed in separate issues.

Speaking of functions only:

I strongly agree that external variable access must be lexically scoped. Allowing a function to access something from an unknown caller makes the behavior totally unpredictable. I assume dynamic scoping is just a legacy thing that should be completely avoided today.

Tab's `using()` still looks like dynamic scoping to me, as the function still doesn't know where the variables are from.

---

Alternative idea: allow nested functions (and make the language more functional)

Example:
```css
@function --outer(--foo) {
  /* declares a --foo argument */
  @function --inner() {
    /* captures --foo from the outer scope, same way how capturing works in many other languages */
    result: calc(var(--foo) / 2);
  }
  result: calc(var(--foo) + --inner());
}
@function --outer2() {
  /* captures --foo from the "global" scope, which is the element's custom properties */
  result: calc(var(--foo) / 2);
}
.foo {
  --foo: 1;
  width: calc((--outer(10) + --outer2()) * 1px); /* (15 + 0.5) * 1px */
}
```

And I don't mind having `arg()` if that addes more clarity.

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


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 1 March 2024 10:34:19 UTC