bind-data-deconstructors-macros   scheme


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

Implementation

(define (bind-data-deconstructors-macros n type constructors)
  ;; (println 'datadecont 'n n 'type type 'constructors constructors)
  (map (lambda (x num)
         (let ((nm (symbol->string (car x)))
               (args (map (lambda (x) (string->symbol (string-append "a" (number->string x)))) (range (length (cdr x)))))
               (getter (string->symbol (string-append (symbol->string n) "_get_" (symbol->string (car x))))))
           `(bind-macro (,(string->symbol (string-append nm "$")) obj args success fail)
              (list ',(string->symbol (string-append nm "_Dstrct"))
                    obj
                    (list 'lambda (map (lambda (x n)
                                    (if (= 95 (char->integer (string-ref (symbol->string x) 0)))
                                        (string->symbol (string-append "argx" (atom->string n)))
                                        x))
                                  args
                                  (range (length args)))
                          success)
                    (list 'lambda '() fail)))))
       constructors
       (range (length constructors))))


Back to Index