[gambit-list] equiv of __FILE__ and __LINE__
Marc Feeley
feeley at iro.umontreal.ca
Thu May 7 09:48:02 EDT 2009
On 7-May-09, at 3:06 AM, lowly coder wrote:
> Let's see how much of this I can understand.
>
> 1) FILE & LINE are macros.
Yes.
> 2) in (lambda (src <-- this variable here
> the src is linked to the reader/parser object, which is why we
> can query it for the current line / file number?
Yes. The parameter is the "source object" corresponding to the macro
call. What is a source object? Here's a simple way to find out how
source objects are represented:
bash-3.2$ gsi
Gambit v4.4.3
> (define x #f)
> (##define-syntax foo (lambda (src) (set! x src) '(begin)))
> (foo (stuff) turkey)
> x
#(#(source1)
(#(#(source1) foo (console) 65538)
#(#(source1) (#(#(source1) stuff (console) 393218)) (console)
327682)
#(#(source1) turkey (console) 851970))
(console)
2)
> (##source? x)
#t
> (##source-locat x)
#((console) 2)
> (##source-code x)
(#(#(source1) foo (console) 65538)
#(#(source1) (#(#(source1) stuff (console) 393218)) (console) 327682)
#(#(source1) turkey (console) 851970))
> (length (##source-code x))
3
> (##source-code (car (##source-code x)))
foo
> (##source-code (car (##source-code (cadr (##source-code x)))))
stuff
> (##desourcify x)
(foo (stuff) turkey)
> (##locat-container (##source-locat x))
(console)
> (##locat-position (##source-locat x))
2
> (##display-locat (##source-locat x) #t (current-output-port))
(console)@3.1
> 3) Why the ##'s
All the ## names refer to internal functionality that should be used
with great care, and is not meant for use by a casual user. The
procedures typically don't do any type checking and the API may change
at any point. The ## stresses these point in several ways:
1) It is easy to spot in code, so a simple "grep '##' *.scm" will find
places in your code that are possibly unsafe or brittle (over versions
of Gambit).
2) The ## prefix is "ugly" and may be a deterrent to using these names.
3) The "##" prefix on symbols is illegal in Scheme, so it is clear
that by using these names you are definitely non-portable to other
Schemes (it turns out that Chicken Scheme supports this extension, so
## is not completely non-portable anymore).
Marc
More information about the Gambit-list
mailing list