bind-data-constructors   scheme


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

Implementation

(define (bind-data-constructors n type constructors)
  ;; (println 'datacont 'n n 'type type 'constructors constructors)
  (map (lambda (x num)
         (let ((args (map (lambda (x) (string->symbol (string-append "a" (number->string x)))) (range (length (cdr x)))))
               (tuplename (string->symbol (string-append (symbol->string n) "_data_" (symbol->string (car x))))))
           `(bind-func ,(constructor-name-and-type n type x)
              (lambda ,(if (null? args) '() args)
                (let ((obj (,tuplename ,@(if (null? args) (list 0) args))))
                  (,(string->symbol (string-append (symbol->string n) "_Make")) ,num (cast obj i8*)))))))
       constructors
       (range (length constructors))))


Back to Index