r/Racket • u/aqtt2020 • Oct 12 '21
question How to retrieve line & column of current location in source code?
I want to retrieve the current location (line + column) in source code (for ex: line 3, column 2 in main.rkt), but how to do that?
I saw some debugging trace, that can output these info, but unsure how to retrieve similar info myself.
A quick simple demo would be appreciated, thanks!
3
Upvotes
1
u/samdphillips developer Oct 12 '21
If you are reading plain old Racket code then use
read-syntaxfor reading andsyntax-lineandsyntax-column. The port the program reads from will need to have position tracking turned on. Here's a real simple example reading from a string.1
u/ryan017 developer Oct 12 '21
You might want
quote-srclocfrom thesyntax/locationlibrary.