In typst I want to write code that does something if the current location is at (or close to) the left-hand margin.
How can I get the value of the current page margins as numbers?
For example, the code below does what I want with the default 25mm margins, but I want it to work with arbitrary page margins. So I want to change the hard-coded 25 to a function which returns the current left margin value, in mm, as a number.
#let lr() = locate(l=>if l.position().x.mm()<=25 [*left* ] else [_right_ ])
#let n = 0
#while n < 100 {
n = n+1
[#lr()]
}

Why not just put a label at the start of your page as a reference for the left margin?
However, if you're here from Google and want to get the page margins for a different reason, keep reading.
Getting page margins
This is not currently possible without unstable hacks. You can track the status of https://github.com/typst/typst/issues/763 for when this is supported by the language.
In the meantime, you can use the following if you really need margin values:
The
marginstate will hold your page margins as a dictionary.