This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Klaus Schilling <Klaus.Schilling@home.ivm.de> writes: > Are there any working examples out there how to define read and write-syntaxes > for interfaces defined with pint? I think I've understood you right, so here goes: <REPL> guile> (define-module (rw-test) #:use-module (oo interface)) #<directory rw-test 401c0980> guile> (define-interface-type <rw-number> "readable and writable number" ;; inherits from these two guys: (<readable> <writable>) ;; no constructors: () ;; one new method: (invert!)) guile> (define-interface-mapping plain-number-mapping "rw for plain numbers" <rw-number> ;; here, only invert! is defined, ;; because the default implementations of ;; make/port & write are just fine. #:invert! (lambda (interface) (set-interface-data! interface (- 0 (interface-data interface))))) ;; read a number from port: guile> (define num (make-interface/port plain-number-mapping)) ;; this is the input: 123 ;; now check what we've just read: guile> num #<interface (#<mapping "rw for plain numbers" (type: "readable and writable number")> data: 123)> ;; invert it: guile> (rw-number-invert! num) ;; write it back: guile> (write-interface num) -123 </REPL> Now, I think what really confused you is that the current version of PINT has bugs in the definitions of <readable> and <writable>, so the above doesn't work :(. That's what you get when you don't test everything... I'm uploading the fixed version right now, snarf it when it gets out of the incoming directory. > Klaus Schilling Nice to know that somebody is actually trying to use this stuff. mike.