[Larceny-users] [long] identifier bindings and visibility across phases

Marco Maggi marco.maggi-ipsu at poste.it
Sun Oct 4 07:09:27 EDT 2009


Ciao,

  I am trying to implement  an expansion time feature for my
R6RS  libraries;   basically  it  works   like  this,  using
identifier macros:

(define-record-extension <string>
  (fields (length string-length #f)
          (upcase string-upcase #f)
          (dncase string-downcase #f)))

(let ((S "Ciao"))

  (with-virtual-fields ((length <string> S))
    length)
  ; => 4

  (with-virtual-fields (((upcase dncase) <string> S))
    (list upcase dncase))
  ; => ("CIAO" "ciao"))

I have prepared an  archive of test files[1] with everything
in it, which can be  downloaded from the "Downloads" page of
Nausicaa[2].

  As the tests show, the basic feature works when the record
extension  is in the  same file  that makes  use of  it; but
there  is a  problem  when  the extension  is  defined in  a
library ("lib-test-2.sls").

  With the test in "test.sps":

(with-virtual-fields ((def <beta> o))
  def)

I get the following error:

------------------------------------------------------------

Syntax violation: invalid reference

No binding available for beta-def-ref in library (...program...)

Form: beta-def-ref

Trace:

  (beta-def-ref the-record)

  def

  (lambda (the-record)
  (let-syntax
    ((def (identifier-syntax
            (_ (beta-def-ref the-record))
            ((set! _ e) (beta-def-set! the-record e)))))
    (with-virtual-fields () (set! def '(90 91)) def)))

  ((lambda (the-record)
   (let-syntax
     ((def (identifier-syntax
             (_ (beta-def-ref the-record))
             ((set! _ e) (beta-def-set! the-record e)))))
     (with-virtual-fields () (set! def '(90 91)) def)))
 o)

  (let-syntax
  ((dummy (lambda (stx)
            (syntax-case
              stx
              ()
              ((_ ?kontext)
               (let ((RTD (record-type-descriptor <beta>)))
                 (with-syntax
                   (((EXPR) (datum->syntax #'?kontext '(o)))
                    ((VAR ...) (datum->syntax #'?kontext '(def)))
                    ((ACCESSOR ...)
                     `(,(%virtual-field-accessor '<beta> RTD 'def)))
                    ((MUTATOR ...)
                     `(,(%virtual-field-mutator '<beta> RTD 'def)))
                    ((FORMS ...)
                     (datum->syntax
                       #'?kontext
                       '((with-virtual-fields () (set! def '(90 91)) def)))))
                   #'(let ((the-record EXPR))
                       (let-syntax
                         ((VAR (identifier-syntax
                                 (_ (ACCESSOR the-record))
                                 ((set! _ e) (MUTATOR the-record e))))
                          ...)
                         FORMS
                         ...)))))))))
  (dummy <beta>))

  (with-virtual-fields
  ((((def def)) <beta> o))
  (with-virtual-fields () (set! def '(90 91)) def))

  (with-virtual-fields
  (((def) <beta> o))
  (set! def '(90 91))
  def)

  (write (with-virtual-fields
         (((def) <beta> o))
         (set! def '(90 91))
         def))

  (lambda (o)
  (write (with-virtual-fields ((def <beta> o)) def))
  (newline)
  (write (with-virtual-fields
           (((def) <beta> o))
           (set! def '(90 91))
           def))
  (newline))

  ((lambda (o)
   (write (with-virtual-fields ((def <beta> o)) def))
   (newline)
   (write (with-virtual-fields
            (((def) <beta> o))
            (set! def '(90 91))
            def))
   (newline))
 (make <beta> 1 2 3 4 5 6))


Error: no handler for exception #<record &compound-condition>
Compound condition has these components:
#<record &who>
    who : "invalid reference"
#<record &message>
    message : "No binding available for beta-def-ref in library (...program...)"
#<record &syntax>
    form : beta-def-ref
    subform : #f

Terminating program execution.

------------------------------------------------------------

the test  fully works with Ikarus and  Ypsilon (and probably
it will work with Mosh, too, when Issue 102 is solved); only
Larceny fails, so  I understand it is a  phasing problem.  I
am  not  able  to   understand  how  to  change  the  import
specifications of the libraries to make the code work; I am
still learning how phasing works...

  Anyway, in the definition of DEFINE-RECORD-EXTENSION I do:

    (datum->syntax #'?kontext '?accessor)

where,   IMHO,   "?kontext"   holds  the   correct   context
informations to  make everything work,  whatever the context
in which  the output form of WITH-VIRTUAL-FIELDS  ends up to
be.

  What is wrong?

TIA

[1] <http://cloud.github.com/downloads/marcomaggi/nausicaa/virtual-fields.tar.gz>
[2] <http://github.com/marcomaggi/nausicaa/downloads>
-- 
Marco Maggi



More information about the Larceny-users mailing list