+(define-macro (primitive header . body)
+ (let* ((type (car header))
+ (args (cdr header))
+ (list-args (names-arguments args)))
+ `(lambda* ,args
+ (let ((m (make-mesh
+ ',type
+ (lambda (props)
+ (apply (lambda* ,(cons #:key list-args) ,@body)
+ (list
+ ,@(let get-params ((l list-args))
+ (cond ((null? l) '())
+ (else
+ (cons (symbol->keyword (car l))
+ (cons `(assoc-ref props ',(car l))
+ (get-params (cdr l)))))))))))))
+ (mesh-properties-set! m (list ,@(map (lambda (a) `(cons ',a ,a)) list-args)))
+ m))))
+
+(define-macro (define-primitive header . body)
+ `(define ,(car header) (primitive ,header ,@body)))
+
+
+;;; Primitives definition
+
+(define-primitive (square size #:key texture color)