Last active
          October 30, 2025 16:28 
        
      - 
      
- 
        Save fogus/84d55d04979f2cbe82ad305c41661795 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
    
  
  
    
  | (defn eval-expr [expr env] | |
| (cond (symbol? expr) (env expr) | |
| (and (seq? expr) (= 'lambda (first expr))) | |
| (let [[_ [a] body] expr] | |
| (fn [arg] | |
| (eval-expr body (fn [x] (if (= a x) | |
| arg | |
| (env x)))))) | |
| (seq? expr) | |
| (let [rtor (eval-expr (first expr) env) | |
| rnd (eval-expr (second expr) env)] | |
| (rtor rnd)) | |
| :else | |
| (throw (ex-info "uncool" {:expr expr})))) | |
| ;; test code | |
| (eval-expr '((lambda (n) n) hello) {'hello "hi!"}) | |
| (eval-expr '(((lambda (x) | |
| (lambda (y) | |
| x)) | |
| foo) | |
| bar) | |
| '{foo 1, bar 2}) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment