Skip to content

Add default parameter for array.{first, last}#5970

Merged
laurmaedje merged 2 commits intotypst:mainfrom
bluebear94:mf/array-first-last-defaults
Mar 31, 2025
Merged

Add default parameter for array.{first, last}#5970
laurmaedje merged 2 commits intotypst:mainfrom
bluebear94:mf/array-first-last-defaults

Conversation

@bluebear94
Copy link
Contributor

Closes #5960.

@laurmaedje laurmaedje added interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. scripting About Typst's coding capabilities labels Mar 24, 2025
@laurmaedje
Copy link
Member

As mentioned in #5960 (comment), I'm not a fan of optional handling in Typst and the proliferation of default arguments, but given that there is no solution for that in sight, I guess this is still an improvement compared to the status quo. And if we come up with something better, we can deprecate all of them together.

One alternative route would be to return none for not present, but I think that's worse as it means you can't distinguish not present vs. none. (Which is probably how JS ended up with undefined and null, which are the bane of my existence.) It's just a hard problem in dynamic languages as they can't represent Option<Option<T>>.

@laurmaedje laurmaedje added this pull request to the merge queue Mar 31, 2025
Merged via the queue into typst:main with commit a64af13 Mar 31, 2025
6 checks passed
hongjr03 pushed a commit to hongjr03/typst that referenced this pull request Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. scripting About Typst's coding capabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array.{first,last} default argument in value position

3 participants