~ chicken-core (chicken-5) 34345a5f048ecf8efa39c481d32878fea4cda83b
commit 34345a5f048ecf8efa39c481d32878fea4cda83b Author: felix <felix@call-with-current-continuation.org> AuthorDate: Wed Oct 20 04:20:25 2010 -0400 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Wed Oct 20 04:20:25 2010 -0400 blob literal syntax (uses sharp-dollar now) diff --git a/library.scm b/library.scm index ab03df94..7008e5a4 100644 --- a/library.scm +++ b/library.scm @@ -2709,7 +2709,11 @@ EOF (list 'quasisyntax (readrec)) ) ((#\$) (##sys#read-char-0 port) - (list 'location (readrec)) ) + (let ((c (##sys#peek-char-0 port))) + (cond ((char=? c #\{) + (##sys#read-char-0 port) + (##sys#read-bytevector-literal port)) + (else (list 'location (readrec)) )))) ((#\:) (##sys#read-char-0 port) (build-keyword (r-token)) ) @@ -2825,7 +2829,6 @@ EOF ;; I put it here, so the SRFI-4 unit can intercept '#f...' ((#\f #\F) (##sys#read-char-0 port) #f) ((#\t #\T) (##sys#read-char-0 port) #t) - ((#\{) (##sys#read-char-0 port) (##sys#read-bytevector-literal port)) (else (##sys#read-error port "invalid sharp-sign read syntax" char) ) ) ) @@ -3112,11 +3115,15 @@ EOF (outchr port #\space) (out (##sys#slot x 0)) ) ) ((##core#inline "C_bytevectorp" x) - (if (##core#inline "C_permanentp" x) - (outstr port "#<static blob of size") - (outstr port "#<blob of size ") ) - (outstr port (number->string (##core#inline "C_block_size" x))) - (outchr port #\>) ) + (outstr port "#${") + (let ((len (##sys#size x))) + (do ((i 0 (fx+ i 1))) + ((fx>= i len)) + (let ((b (##sys#byte x i))) + (when (fx< b 16) + (outchr port #\0)) + (outstr port (##sys#number->string b 16))))) + (outchr port #\}) ) ((##core#inline "C_structurep" x) (##sys#user-print-hook x readable port)) ((##core#inline "C_closurep" x) (outstr port (##sys#procedure->string x))) ((##core#inline "C_locativep" x) (outstr port "#<locative>")) diff --git a/manual/Non-standard read syntax b/manual/Non-standard read syntax index 85095ae4..fa2f63ea 100644 --- a/manual/Non-standard read syntax +++ b/manual/Non-standard read syntax @@ -39,6 +39,17 @@ Allows user-defined extension of external representations. (For more information An abbreviation for {{(location EXPRESSION)}}. +=== "Blob" literals + + #${HEX ...} + +Syntax for literal "blobs" (byte-sequences). Expects hexadecimal digits and ignores +any whitespace characters: + + #;1> ,d '${deadbee f} + blob of size 4: + 0: de ad be ef .... + === Keyword #:SYMBOLTrap