[gambit-list] three questions regarding gambit low level

Marc Feeley feeley at iro.umontreal.ca
Sat Dec 21 09:41:10 EST 2019


> On Dec 21, 2019, at 8:48 AM, Hendrik Boom <hendrik at topoi.pooq.com> wrote:
> 
> On Sat, Dec 21, 2019 at 07:20:32AM -0500, Marc Feeley wrote:
>> Hello Jorg,
>> 
>>> On Dec 17, 2019, at 8:30 AM, Jörg F. Wittenberger <Joerg.Wittenberger at softeyes.net> wrote:
>>> 
>>> Hi all,
> 
>> 
>> With the default thread scheduler, or the SMP thread scheduler when there is a single processor (runtime option -:p1) you can disable the scheduler’s thread preemption interrupt by using the (declare (not interrupts-enabled)) declaration.  When that declaration is in effect, the compiler will no longer add interrupt checking code in the generated code. Note however that if there is a call to a procedure that wasn’t compiled with this declaration then the thread scheduler may interrupt its execution.
>> Moreover disabling interrupt checking is tricky because stack overflows are 
>> detected using the same mechanism, so you have to make sure the code does not 
>> add more than a few stack frames.
> 
> I conclude that tail-calls will not add stack frames, not even temporary ones that 
> can get garbage-collected when the stack is full.  Otherwise this won't work.

Your conclusion is correct.  Tail call = no additional stack frame (or to put it another way, the current stack frame is immediately garbage collected at the moment of the control transfer).

> 
>> 
>>> 
>>> 2. Defining yet another record type.  Much like SRFI-9 just two actual
>>> slots per record field, the value and a version tag.  Likely doable, but
>>> the tricky part: how do I hide the version tag accessors from user code?
>> 
>> Gambit’s define-type can assign various properties to the fields, including whether the field is printed or not, whether the field is read-only, whether its content is checked by the equal? procedure, what the initial value of the field is, etc
>> 
>> A plain definition of a 2d point record can be done like this:
>> 
>> (define-type point
>>  x
>>  y)
>> 
>> It implicitly defines the procedures make-point, point-copy, point?, point-x, point-x-set!, point-x-set, point-y, point-y-set!, point-y-set.  Both fields will be shown when a point is printed:
>> 
>>> (make-point 1 2)
>> #<point #2 x: 1 y: 2>
>> 
>> If you want two other hidden fields for the version tags of x and y, you could define the record like this:
>> 
>> (define-type point
>>  x
>>  y
>>  (x-version unprintable: equality-skip: no-functional-setter: init: #f)
>>  (y-version unprintable: equality-skip: no-functional-setter: init: #f))
> 
> As I always wonder with Racket, I find myself wondering how much of this stuff
> is standard Scheme and how much is Gambit-specific.
> It would be lovely to program in a common subset fo the two, because I like 
> Gambit, but Drracket is a very convenient development environment.

Gambit/Racket unification is not (yet) on my TODO.  Gerbil has gone part of the way there, so maybe some of the Gerbil goodness should be ported back to Gambit so that all users can benefit.

Marc





More information about the Gambit-list mailing list