Your response to 2 was really enlightening.
More on 3:
~:$ cat test.scm
(define source? 10)
(define ##source? 10)
(pp source?)
(pp ##source?)
~:$ gsi test.scm
10
10
This surprised me a bit ... initially, intuitively, I had a notion that ##blah was a blah that had it's value hard coded internally in gambit (so that even if the user did weird things to his/her environment, I can still get the 'system functions').
In gambit, are ##-vars treated just like regular ##-vars ?
I see the ##'s pop up alot in the gambit internal *.scm 's, and sometimes, changing a "##blah" to a "blah" results in the code behaving differently (iirc when I was trying to get the debugger to output a 'stack trace').
Yes.
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. 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:
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?
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