Next: , Previous: , Up: Debugging   [Contents][Index]


6.27.2 Source Properties

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) and xxx at the Guile prompt (where the variable xxx has not been defined):

scheme@(guile-user)> (xxx)
<unnamed port>:4:1: In procedure module-lookup:
<unnamed port>:4:1: Unbound variable: xxx

scheme@(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.

Scheme Procedure: supports-source-properties? obj
C Function: scm_supports_source_properties_p (obj)

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.

Scheme Procedure: set-source-properties! obj alist
C Function: scm_set_source_properties_x (obj, alist)

Install the association list alist as the source property list for obj.

Scheme Procedure: set-source-property! obj key datum
C Function: scm_set_source_property_x (obj, key, datum)

Set the source property of object obj, which is specified by key to datum. Normally, the key will be a symbol.

Scheme Procedure: source-properties obj
C Function: scm_source_properties (obj)

Return the source property association list of obj.

Scheme Procedure: source-property obj key
C Function: scm_source_property (obj, key)

Return the property specified by key from obj’s source properties.

If the positions reader option is enabled, supported expressions will have values set for the filename, line and column properties.

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 more.

Guile also defines a couple of convenience macros built on syntax-source:

Scheme Syntax: current-source-location

Expands to the source properties corresponding to the location of the (current-source-location) form.

Scheme Syntax: current-filename

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:

Scheme Procedure: cons-source xorig x y
C Function: scm_cons_source (xorig, x, y)

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.


Next: , Previous: , Up: Debugging   [Contents][Index]