aboutsummaryrefslogtreecommitdiffstats
path: root/byte.scm
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:26 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:26 -0800
commitf24b9140d6f74804d5599ec225717d38ca443813 (patch)
tree0da952f1a5a7c0eacfc05c296766523e32c05fe2 /byte.scm
parent8ffbc2df0fde83082610149d24e594c1cd879f4a (diff)
downloadslib-f24b9140d6f74804d5599ec225717d38ca443813.tar.gz
slib-f24b9140d6f74804d5599ec225717d38ca443813.zip
Import Upstream version 2c0upstream/2c0
Diffstat (limited to 'byte.scm')
-rw-r--r--byte.scm14
1 files changed, 14 insertions, 0 deletions
diff --git a/byte.scm b/byte.scm
new file mode 100644
index 0000000..3d091ce
--- /dev/null
+++ b/byte.scm
@@ -0,0 +1,14 @@
+;;; "byte.scm" small integers, not necessarily chars.
+
+(define (byte-ref str ind) (char->integer (string-ref str ind)))
+(define (byte-set! str ind val) (string-set! str ind (integer->char val)))
+(define (make-bytes len . opt)
+ (if (null? opt) (make-string len)
+ (make-string len (integer->char (car opt)))))
+(define (write-byte byt . opt) (apply write-char (integer->char byt) opt))
+(define (read-byte . opt)
+ (let ((c (apply read-char opt)))
+ (if (eof-object? c) c (char->integer c))))
+(define (bytes . args) (list->bytes args))
+(define (bytes->list bts) (map char->integer (string->list bts)))
+(define (list->bytes lst) (list->string (map integer->char lst)))