Commits

Anonymous committed b871024

Modify example in readme.

Comments (0)

Files changed (3)

 scheme-bert
 ===========
 
-scheme-bert is a BERT (Binary ERlang Term) serialization library for Scheme implementations compliant to [R^6RS](http://www.r6rs.org/). BERT is based on Erlang's [External Term Format](http://www.erlang.org/doc/apps/erts/erl_ext_dist.html).
+scheme-bert is a BERT (Binary ERlang Term) serialization library for Scheme implementations compliant to [R^6RS](http://www.r6rs.org/implementations.html). BERT is based on Erlang's [External Term Format](http://www.erlang.org/doc/apps/erts/erl_ext_dist.html).
 
 See the BERT specification at [bert-rpc.org](http://bert-rpc.org).
 
 
 Usage
 -----
-
-Issue `(import (scheme-bert))` in your REPL or put this in head of your source file.
-You will also probably want to import some other libraries such as `bytevectors`.
 
-    > (bert-encode (vector 'foo 42 666 (vector 12 '() (vector 255 'bar) 111222333444555666)))
-    #"\203h\4d\0\3fooa*b\0\0\2\232h\4a\fjh\2a\377d\0\3barn\b\0\222\203\r|\37$\213\1"
+Issue `(import (scheme-bert))` in your REPL or put this in head of your source file.
+You will also probably want to import some other libraries such as `bytevectors`.
 
-    > (bert-decode #"\203m\0\0\0001Most people would rather die than think; many do.")
-    "Most people would rather die than think; many do."    
+    > (define (bytes)
+        (bert-encode (list 'foo 13 42 (vector 666 '() 'bar))))
+    > (bytes)
+    #"\203l\0\0\0\4d\0\3fooa\ra*h\3b\0\0\2\232jd\0\3barj"
+    > (bert-decode (bytes))
+    {foo 13 42 #(666 () bar)}
+    >
 
 Caveats
 -------
 
 Trivia
 ------
-Please, [drop me an email](yarsanukaev AT gmail DOT com) if you used or intend to use the library in your project ;-)
+Please, drop me an email if you used or intend to use the library in your project ;-)
 
 Copyright
 ---------
 
-Copyright (c) 2010 Yasir M. Arsanukaev. See LICENSE for details.
+Copyright (c) 2010 Yasir M. Arsanukaev. See LICENSE for details.
+

src/scheme-bert.ss

                  (rnrs arithmetic flonums)
                  (rnrs r5rs)
                  (rnrs unicode)
-                 ;; Either import SRFI 19 or use 
-                 ;; builtin functions (as in Chez Scheme))
-                 (srfi :19)
+                 ;; Uncomment next line if you use Racket
+                 ;(srfi :19)
+                 ;; Uncomment next line if you use Chez Scheme
                  ;(only (chezscheme) time-nanosecond time-second time? make-time)
                  )
          
         (rnrs)
         (rnrs bytevectors)
         (rnrs io ports)
-        ;; Either import SRFI 19 or use 
-        ;; builtin functions (as in Chez Scheme))
-        (srfi :19)
+        ;; Uncomment next line if you use Racket
+        ;(srfi :19)
+        ;; Uncomment next line if you use Chez Scheme
         ;(only (chezscheme) time-nanosecond time-second time? make-time)
         )
 
-; calling of these procs independently is useful: 
+; Calling of these procs independently is useful for testing purposes:
 ; test-encoder, test-decoder, test-roundtrip
 
 (define (fold/and proc lst)
 
 (define (checkthis testname expect exprresult)
   (if (equal? expect exprresult)
-      #t
-      (begin
-        (display (string-append testname ": failed"))
-        (newline)
-        #f)))
+    #t
+    (begin
+      (display (string-append testname ": failed"))
+      (newline)
+      #f)))
 
 (define (test-group tests)
   (let* ((result (map (lambda (x) (x)) tests))
 (define (checkthis-bert datum)
   (lambda ()
     (checkthis (call-with-string-output-port
-                (lambda (outport) (display datum outport))) 
+                 (lambda (outport) (display datum outport))) 
                (bert-decode (bert-encode datum))
                datum)))
 
   ; {foo,42,666,{12,[],{255,'Bar'},111222333444555666}}
   (checkthis "test-encoder-1"
              (u8-list->bytevector '(131 104 4 100 0 3 102 111 111 97 42 
-                                        98 0 0 2 154 104 4 97 12 106 104 
-                                        2 97 255 100 0 3 98 97 114 110 8 
-                                        0 146 131 13 124 31 36 139 1))
+                                    98 0 0 2 154 104 4 97 12 106 104 
+                                    2 97 255 100 0 3 98 97 114 110 8 
+                                    0 146 131 13 124 31 36 139 1))
              (bert-encode 
-              (vector 'foo 42 666 
-                      (vector 12 '() 
-                              (vector 255 'bar) 111222333444555666)))))
+               (vector 'foo 42 666 
+                       (vector 12 '() 
+                               (vector 255 'bar) 111222333444555666)))))
 
 (define (test-encoder-time)
   ; {bert, time, <some_day_bleh>}
   (checkthis "test-encoder-time"
              (bert-encode (make-time 'time-utc 42424242 502806141))
              (u8-list->bytevector '(131 104 5 100 0 4 98 101 114 
-                                        116 100 0 4 116 105 109 101
-                                        98 0 0 1 246 98 0 12 76 253
-                                        98 0 0 165 184))))
+                                    116 100 0 4 116 105 109 101
+                                    98 0 0 1 246 98 0 12 76 253
+                                    98 0 0 165 184))))
 
 (define (test-bignum)
   ; http://goo.gl/E9od   Haha
   (checkthis "test-bignum"
              (bert-encode 
-              54308428790203478762340052723346983453487023489987231275412390872348475)
+               54308428790203478762340052723346983453487023489987231275412390872348475)
              (u8-list->bytevector '(131 110 30 0 59 247 203 187 60 
-                                        16 162 156 242 204 91 91 185 
-                                        157 61 237 199 186 60 55 104 
-                                        86 102 152 206 95 93 105 222 7))))
+                                    16 162 156 242 204 91 91 185 
+                                    157 61 237 199 186 60 55 104 
+                                    86 102 152 206 95 93 105 222 7))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Decoder test cases
   (checkthis "test-decoder-string"
              "Flying Spaghetti Monster"
              (bert-decode
-              (u8-list->bytevector '(131 109 0 0 0 24 70 108 121 105 
-                                         110 103 32 83 112 97 103 104 
-                                         101 116 116 105 32 77 111 110 
-                                         115 116 101 114)))))
+               (u8-list->bytevector '(131 109 0 0 0 24 70 108 121 105 
+                                      110 103 32 83 112 97 103 104 
+                                      101 116 116 105 32 77 111 110 
+                                      115 116 101 114)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Roundtrip (encode->decode and vice versa) test cases
     (let ((h2 (bert-decode (bert-encode h1))))
       (let-values (((keys1 vals1) (hashtable-entries h1))
                    ((keys2 vals2) (hashtable-entries h2)))
-        (checkthis "test-hash" #t
-                   (and
-                    (fold/and (lambda (x) (member x (vector->list keys2)))
-                              (vector->list keys2))
-                    (fold/and (lambda (x) (member x (vector->list vals2)))
-                              (vector->list vals2))))))))
+                  (checkthis "test-hash" #t
+                             (and
+                               (fold/and (lambda (x) 
+                                           (member x (vector->list keys2)))
+                                         (vector->list keys2))
+                               (fold/and (lambda (x) 
+                                           (member x (vector->list vals2)))
+                                         (vector->list vals2))))))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.