plet   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/base/pattern.xtm

Implementation

;; Matches patterns against datums, and executes c{body} in an environment
;; with pattern variables bound. For example, here's how
;; one might use c{plet} to implement vector addition, where a vector is a
;; cons pair:
;; <pre>
;; (define vec1 (cons 1 2))
;; ;Value: vec1
;;
;; (define vec2 (cons 3 4))
;; ;Value: vec2
;;
;; (define (vector-add x y)
;;   (plet (((?x1 . ?x2) x)
;;          ((?y1 . ?y2) y))
;;         (cons (+ x1 y1) (+ x2 y2))))
;; ;Value: vector-add
;;
;; (vector-add vec1 vec2)
;; ;Value 86: (4 . 6)
;;</pre>
;; @args ({(pattern datum)}) body
(define-syntax plet
  (er-macro-transformer
   (lambda (expr rename compare)
     (let ((pattern-pairs (cadr expr))    ; pattern-pairs := {(pattern_i datum_i)}
           (body          (cddr expr)))   ; body of the plet (everything after pattern-pairs)
       (cond ((null? pattern-pairs) `(let () ,@body)) ; no patterns to match, i.e. (plet () body)


Back to Index

Similar Entries

  • impc:ti:completely-unwrap-named-type    scheme
  • plet*    scheme
  • plet-make-bindings    scheme