File: byte.scm

package info (click to toggle)
slib 2c7-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,216 kB
  • ctags: 1,613
  • sloc: lisp: 19,483; makefile: 334; sh: 144
file content (15 lines) | stat: -rw-r--r-- 708 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
;;; "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 bytes-length string-length)
(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)))