5. Bigloo -- Standard Library<BR>5.4 Serialization

5. Bigloo -- Standard Library
5.4 Serialization

Browsing

Home: Bigloo
A ``practical Scheme compiler''
for Bigloo version 2.5a
April 2002

Previous chapter: Core Language
Next chapter: Pattern Matching


Standard Library

5.1 Scheme Library
5.2 Input and output
5.3 Structures and Records
5.4 Serialization
5.5 Bit manipulation
5.6 Hash Tables
5.7 System programming
5.8 Process support
5.9 Socket support
5.10 Posix Regular Expressions


Chapters

Copyright
Acknowledgements
1. Table of contents
2. Overview of Bigloo
3. Modules
4. Core Language
5. Standard Library
6. Pattern Matching
7. Object System
8. Threads
9. Regular parsing
10. Lalr(1) parsing
11. Errors and Assertions
12. Eval and code interpretation
13. Macro expansion
14. Command Line Parsing
15. Explicit typing
16. The C interface
17. The Java interface
18. Bigloo Libraries
19. SRFIs
20. DSSSL support
21. Compiler description
22. User Extensions
23. Bigloo Development Environment
24. Global Index
25. Library Index
Bibliography


string->obj stringbigloo procedure
This function converts a string which has been produced by obj->string into a Bigloo object.

obj->string objectbigloo procedure
This function converts into a string any Bigloo object which does not contain a procedure.

The implementation of the last two functions ensures that for every Bigloo object obj (containing no procedure), the expression:

(equal? obj (string->obj (obj->string obj)))
   => #t
binary-port? objbigloo procedure
open-output-binary-file file-namebigloo procedure
append-output-binary-file file-namebigloo procedure
open-input-binary-file file-namebigloo procedure
close-binary-port binary-portbigloo procedure
input-obj binary-portbigloo procedure
output-obj binary-port objbigloo procedure
input-char binary-portbigloo procedure
output-char binary-port charbigloo procedure
Bigloo allows Scheme objects to be dumped into, and restored from, files. These operations are performed by the previous functions. The dump and the restore use the two functions obj->string and string->obj.

It is also possible to use a binary file as a flat character file. This can be done by the means of output-char and input-char functions.

register-procedure-serialization serializer unserializerbigloo procedure
There is no existing portable method to dump and restore a procedure. Thus, if obj->string is passed a procedure, it will emit an error message. Sometime, using strict restrictions, it may be convenient to use an ad-hoc framework to serialize and unserialize procedures. User may specify there own procedure serializer and unserializer. This is the role of register-procedure-serialization. The argument serializer is a procedure of one argument, converting a procedure into a characters strings. The argument unserializer is a procedure of one argument, converting a characters string into a procedure. It belongs to the user to provide correct serializer and unserializer.

Here is an example of procedure serializer and unserializer that may be correct under some Unix platform:

(module foo
   (extern (macro %sprintf::int (::string ::string ::procedure) "sprintf")))

(define (string->procedure str)
   (pragma "(obj_t)(strtoul(BSTRING_TO_STRING($1), 0, 16))" str))

(define (procedure->string proc)
   (let ((item (make-string 10)))
      (%sprintf item "#p%lx" proc)
      item))

(register-procedure-serialization procedure->string string->procedure)

(let ((x 4))
   (let ((obj (cons "toto" (lambda (y) (+ x y)))))
      (let ((nobj (string->obj (obj->string obj))))
         (print ((cdr nobj) 5)))))

get-procedure-serialization bigloo procedure
Returns the a pair whose car is the current procedure serializer and the cdr is the current procedure unserializer.

register-process-serialization serializer unserializerbigloo procedure
Same as register-procedure-serialization for Bigloo processes.

get-process-serialization bigloo procedure
Same as get-procedure-serialization for Bigloo processes.


This
Scribe page has been generated by scribeinfo.
Last update Thu Apr 25 09:40:15 2002