/lib/binary.arc

http://github.com/alimoeeny/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. (load "lib/extend.arc")
  3. (load "lib/scheme.arc")
  4. (extend type (x) (scheme.bytes? x)
  5. 'binary)
  6. (extend ac-literal (x) (errsafe:isa x 'binary)
  7. scheme-t)
  8. (extend coerce (x totype . args) (is totype 'binary)
  9. (case (type x)
  10. binary x
  11. string (scheme.string->bytes/utf-8 x)
  12. (err "Can't coerce" x type)))
  13. (def binary (x)
  14. (coerce x 'binary))
  15. (extend coerce (x totype . args) (isa x 'binary)
  16. (case totype
  17. binary x
  18. string (scheme.bytes->string/utf-8 x)
  19. (err "Can't coerce" x type)))
  20. (extend len (x) (isa x 'binary)
  21. (scheme.bytes-length x))