As Guile reads in Scheme code from file or from standard input, it remembers the file name, line number and column number where each expression begins. These pieces of information are known as the source properties of the expression. Syntax expanders and the compiler propagate these source properties to compiled procedures, so that, if an error occurs when evaluating the transformed expression, Guile’s debugger can point back to the file and location where the expression originated.
The way that source properties are stored means that Guile cannot
associate source properties with individual symbols, keywords,
characters, booleans, or small integers. This can be seen by typing
xxx at the Guile prompt (where the variable
xxx has not been defined):
[email protected](guile-user)> (xxx) <unnamed port>:4:1: In procedure module-lookup: <unnamed port>:4:1: Unbound variable: xxx [email protected](guile-user)> xxx ERROR: In procedure module-lookup: ERROR: Unbound variable: xxx
In the latter case, no source properties were stored, so the error doesn’t have any source information.
Return #t if source properties can be associated with obj, otherwise return #f.
The recording of source properties is controlled by the read option named “positions” (see Scheme Read). This option is switched on by default.
The following procedures can be used to access and set the source properties of read expressions.
Install the association list alist as the source property list for obj.
Set the source property of object obj, which is specified by key to datum. Normally, the key will be a symbol.
Return the source property association list of obj.
Return the property specified by key from obj’s source properties.
positions reader option is enabled, supported expressions
will have values set for the
Source properties are also associated with syntax objects. Procedural
macros can get at the source location of their input using the
syntax-source accessor. See Syntax Transformer Helpers, for
Guile also defines a couple of convenience macros built on
Expands to the source properties corresponding to the location of the
Expands to the current filename: the filename that the
(current-filename) form appears in. Expands to
#f if this
information is unavailable.
If you’re stuck with defmacros (see Defmacros), and want to preserve source information, the following helper function might be useful to you:
Create and return a new pair whose car and cdr are x and y. Any source properties associated with xorig are also associated with the new pair.