# Practical Common Lisp in Racket

**URL:** <https://racket.discourse.group/t/practical-common-lisp-in-racket/1890>\
**Category:** Show & Tell\
**Created:** [April 24, 2023, 10:49pm UTC](https://racket.discourse.group/t/practical-common-lisp-in-racket/1890 "2023-04-24T22:49:02Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ceving](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@ceving](https://racket.discourse.group/u/ceving)\
**Post date:** [November 22, 2023, 4:22pm UTC](https://racket.discourse.group/t/practical-common-lisp-in-racket/1890/5 "2023-11-22T16:22:31Z")

</div>

I think the following macro may be useful to map binary values to symbols.

```scheme
(define-syntax symbolic-binary
  (syntax-rules ()
    ((_ type (sym val) ...)
     (let ((t type))
       (binary
        (lambda (in)
          (let* ((value (read-value t in))
                 (symbol (cond
                           ((equal? value val) 'sym)
                           ...
                           (else (raise-argument-error
                                  'symbolic-binary "invalid value" value)))))
            symbol))
        (lambda (out symbol)
          (let ((value (cond
                         ((eqv? symbol 'sym) val)
                         ...
                         (else (raise-argument-error
                                'symbolic-binary "invalid symbol" symbol)))))
            (write-value t value))))))))

```

It can be used to parse the beginning of a TIFF file.

```scheme
(define-binary-class tiff
  ((endian (endian-binary))
   (type (type-binary)))

  (define (endian-binary)
    (symbolic-binary (iso-8859-1-string 2)
                     (big "MM")
                     (little "II")))

  (define/public (int16-binary)
    (case endian
      ((big) (integer-be 2))
      ((little) (integer-le 2))
      (else (raise-argument-error
             'int16-binary "endian symbol" endian))))

  (define (type-binary)
    (symbolic-binary (send this int16-binary)
                     (tiff 42)
                     (bigtiff 43)
                     (panasonic-rw2 85))))

```

---

_[View the full topic](https://racket.discourse.group/t/practical-common-lisp-in-racket/1890)._
