(defun is-reporter (prim) (eql :reporter (getf prim :type)))
(defun is-command (prim) (eql :command (getf prim :type)))
(defun is-reporter (prim) (eql :reporter (getf prim :type)))
(defun is-command (prim) (eql :command (getf prim :type)))
; Let this grow, slowly but surely, eventually taking on calling context, etc.
; For now, it's just a
; Let this grow, slowly but surely, eventually taking on calling context, etc.
; For now, it's just a
(defun transpile-command-block (block)
`(lambda () ,@(mapcar #'transpile-command (cdr block))))
(defun transpile-command-block (block)
`(lambda () ,@(mapcar #'transpile-command (cdr block))))
(defmacro defprim (name type func)
`(push (list :name ,name :type ,type :func ,func) *prims*))
(defmacro defsimpleprim (name type simple-func)
`(defprim ,name ,type (lambda (&rest args) `(,',simple-func ,@args))))
(defmacro defprim (name type func)
`(push (list :name ,name :type ,type :func ,func) *prims*))
(defmacro defsimpleprim (name type simple-func)
`(defprim ,name ,type (lambda (&rest args) `(,',simple-func ,@args))))
; We count on the parser to handle arguemnts for us, when collating things.
(defsimpleprim := :reporter cl:equalp)
; We count on the parser to handle arguemnts for us, when collating things.
(defsimpleprim := :reporter cl:equalp)
(defsimpleprim :crt :command clnl-nvm:create-turtles)
(defsimpleprim :die :command clnl-nvm:die)
(defsimpleprim :fd :command clnl-nvm:forward)
(defsimpleprim :crt :command clnl-nvm:create-turtles)
(defsimpleprim :die :command clnl-nvm:die)
(defsimpleprim :fd :command clnl-nvm:forward)
+(defprim :if :command (lambda (pred a) `(when ,pred ,@(make-command-block-inline a))))
+(defprim :ifelse :command (lambda (pred a b)
+ `(if ,pred
+ ,@(make-command-block-inline a)
+ ,@(make-command-block-inline b))))
+
+(defprim-alias :if-else :ifelse)
(defsimpleprim :lt :command clnl-nvm:turn-left)
(defsimpleprim :random-float :reporter clnl-nvm:random-float)
(defsimpleprim :rt :command clnl-nvm:turn-right)
(defsimpleprim :lt :command clnl-nvm:turn-left)
(defsimpleprim :random-float :reporter clnl-nvm:random-float)
(defsimpleprim :rt :command clnl-nvm:turn-right)