Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

letbindings should desuger into nested pattern matching #1

Open
swr1bm86 opened this issue May 27, 2016 · 1 comment
Open

letbindings should desuger into nested pattern matching #1

swr1bm86 opened this issue May 27, 2016 · 1 comment
Assignees

Comments

@swr1bm86
Copy link
Owner

e.g.

(let [p1 v1
      p2 v2]
  body)

desuger to

(match v1
  (p1 → (match v2
          (p2 → body))))

this is quite useful when v1 and v2 are just called recursively inside the function itself.

@swr1bm86
Copy link
Owner Author

swr1bm86 commented May 29, 2016

more generally, to support recursive letbindings, should introduce a new special form letrec

(letrec [ev? (λ n → (if (zero? n) true (od? (dec n))))
         od? (λ n → (if (zero? n) false (ev? (dec n))))]
  (begin (print (bool2str (ev? 11)))
         (print (bool2str (ev? 12)))
         (print (bool2str (od? 11)))
         (print (bool2str (od? 12)))))

desuger to

(let [ev? (λ n →
            (match (λ n → (if (zero? n) false (ev? (dec n))))
              (od? → (if (zero? n) true (od? (dec n))))))
      od? (λ n →
            (match (λ n → (if (zero? n) true (od? (dec n))))
              (ev? → (if (zero? n) false (ev? (dec n))))))]
  (begin (print (bool2str (ev? 11)))
         (print (bool2str (ev? 12)))
         (print (bool2str (od? 11)))
         (print (bool2str (od? 12)))))

@swr1bm86 swr1bm86 self-assigned this Aug 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant