Created
          March 13, 2012 18:40 
        
      - 
      
- 
        Save kriyative/2030582 to your computer and use it in GitHub Desktop. 
    Clojure `thrush` operator macro in Common Lisp
  
        
  
    
      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 -> (x &rest args) | |
| "A Common-Lisp implementation of the Clojure `thrush` operator." | |
| (destructuring-bind (form &rest more) | |
| args | |
| (cond | |
| (more `(-> (-> ,x ,form) ,@more)) | |
| ((and (consp form) | |
| (or (eq (car form) 'lambda) | |
| (eq (car form) 'function))) | |
| `(funcall ,form ,x)) | |
| ((consp form) `(,(car form) ,x ,@(cdr form))) | |
| (form `(,form ,x)) | |
| (t x)))) | |
| #+test | |
| (equal (-> 0 | |
| (lambda (x) (+ 1 x)) | |
| (cons 1) | |
| (cons 2)) | |
| '((1 . 1) . 2)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment