Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving calc functions to methods where possible #4032

Open
PgBiel opened this issue Apr 29, 2024 · 1 comment
Open

Moving calc functions to methods where possible #4032

PgBiel opened this issue Apr 29, 2024 · 1 comment
Labels
scripting About Typst's coding capabilities tracking-issue An issue that tracks a larger piece of work.

Comments

@PgBiel
Copy link
Contributor

PgBiel commented Apr 29, 2024

This issue intends to track the progress of migrating calc functions to methods in int and float, as well as other types.

The main reasons behind this effort are to improve organization of those functions - e.g. calc.binom is specific to ints, so it would make sense to invoke it as int.binom instead, much like other operations we have today like sign and bitwise operations -, but also to allow for new, more concise - but optional - syntax (e.g. 5.rem(40) is equivalent to int.rem(5, 40)).

PR #3489 started this effort, in a very general way, attempting to migrate all calc functions to methods.

After several rounds of discussion over Discord, it currently seems wiser to avoid doing that for the moment. In an initial phase, we should consider just migrating methods which unambiguously belong to either int or float, such as int.binom or float.sin. Later on, we could decide how to deal with methods which work with a diversity of types (namely min, max and abs) as well as methods which have differing behavior for ints and floats (such as pow). They could stay in calc as needed, or in more than one place at once; that'd require further discussion.

@laurmaedje
Copy link
Member

sin in particular also operates on angles, so that's something to consider. I like the clean approach of having things as methods, but the arguments in the forge thread against it were also convincing.

@laurmaedje laurmaedje added refactor A refactoring. scripting About Typst's coding capabilities and removed refactor A refactoring. labels Apr 29, 2024
@Enivex Enivex added the tracking-issue An issue that tracks a larger piece of work. label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scripting About Typst's coding capabilities tracking-issue An issue that tracks a larger piece of work.
Projects
None yet
Development

No branches or pull requests

3 participants