Created
April 12, 2011 08:18
-
-
Save amtal/915157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro bin-parser ((cons name raw-clauses) | |
(flet ((fun-clause | |
((list (list* cmd chan match) body) | |
`((,cmd ,chan (binary ,@(: lists map (fun bin-chunk 1) match))) ,body)) | |
((x) (error `(what_is_this ,x)))) | |
(bin-chunk | |
(((list name n)) (when (is_integer n)) | |
`(,name little integer (size ,(* 8 n)))) | |
(((list name 'float)) | |
`(,name little float)) | |
(((list name 'bits)) | |
`(,name bits)) | |
((x) (error `(bad_chunk_spec ,x))))) | |
(let ((clauses (: lists map (lambda (c) (fun-clause c)) raw-clauses))) | |
`(defun ,name ,clauses))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment