/lib/binary.arc
Unknown | 28 lines | 21 code | 7 blank | 0 comment | 0 complexity | c996a22dcfdf742be57950af50fedfb4 MD5 | raw file
1; originally from http://awwx.ws/binary1.arc 2 3(load "lib/extend.arc") 4(load "lib/scheme.arc") 5 6(extend type (x) (scheme.bytes? x) 7 'binary) 8 9(extend ac-literal (x) (errsafe:isa x 'binary) 10 scheme-t) 11 12(extend coerce (x totype . args) (is totype 'binary) 13 (case (type x) 14 binary x 15 string (scheme.string->bytes/utf-8 x) 16 (err "Can't coerce" x type))) 17 18(def binary (x) 19 (coerce x 'binary)) 20 21(extend coerce (x totype . args) (isa x 'binary) 22 (case totype 23 binary x 24 string (scheme.bytes->string/utf-8 x) 25 (err "Can't coerce" x type))) 26 27(extend len (x) (isa x 'binary) 28 (scheme.bytes-length x))