[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SRFI-9 on top of raw structs

From: Ludovic Courtès
Subject: Re: SRFI-9 on top of raw structs
Date: Wed, 09 Dec 2009 01:04:13 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Hi Neil,

Neil Jerram <address@hidden> writes:

> address@hidden (Ludovic Courtès) writes:


>> In the ‘wip-vlist’ branch (which is about implementing Bagwell’s vlists)
>> SRFI-9 is reimplemented in terms of raw structs, instead of records.
> Well I enjoyed a bit of reading, and I don't see any problem with these
> changes, but I don't see why "it makes it easy to write a
> macro-generating macro akin to Dybvig’s ‘define-integrable’".  Couldn't
> that have been achieved just by rewriting the SRFI-9 define-macro as
> define-syntax, but still using make-record-type etc.?

The problem with records is that accessors are defined with
‘record-accessor’, as in:

  (define module-name
    (record-accessor module-type 'name))

Here, ‘record-accessor’ returns a procedure.  Until the compiler has a
smart inliner, each ‘module-name’ call is actually a procedure call.

Conversely, the ‘define-inlineable’ macro in srfi-9.scm leads to
accessor definitions along these lines:

  (define module-name-procedure
    (lambda (x) (struct-ref x 0)))

  (define-syntax module-name
    (lambda (x)
      (syntax-case x ()
        ((_ obj)
         #'(struct-ref obj 0))

Thus, an expression like ‘(module-name (current-module))’ is effectively
expanded to ‘(struct-ref (current-module) 0)’, whereas
‘(procedure? module-name)’ is expanded to ‘(procedure? module-name-procedure)’.

IOW, this is a poor man’s inliner.  But still, I find the approach
pretty neat.  :-)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]