What characters may the names of variables and functions consist of?

What characters may the names of variables and functions consist of? And where can I find this information?

See my answer here: What are the rules for identifiers in Typst? - #2 by xkevio.

2 Likes

If I understand correctly, only these characters are allowed: letters, numbers, “-” and “_”.

This would exclude the question mark. I was wondering whether I could end the name of a predicate function with a question mark (as is usual in LISP/Scheme):

#let isOdd?(num) = ...

That’s indeed not possible. When considering whether that would be worth a syntax change, you also have to consider the interaction with the markup part. For example:

#let date = "Oct 16, 2024"
Do you accept the Terms and Condition, version #date?

With your change, this would result in an unknown variable error.

I’m not on the team, but generally I’d say that the possible benefit is too small to warrant the disruption, especially as a) the is prefix already indicates a predicate imo, and b) Typst is supposed to eventually get type hints, which also help identifying what functions are predicates.

1 Like