From: Frank Duncan Date: Sun, 1 May 2016 19:24:18 +0000 (-0500) Subject: Prims - Implement round X-Git-Tag: v0.1.0~24 X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=commitdiff_plain;h=008caa3;p=clnl Prims - Implement round --- diff --git a/src/main/parse.lisp b/src/main/parse.lisp index 640f8c5..957d177 100644 --- a/src/main/parse.lisp +++ b/src/main/parse.lisp @@ -271,7 +271,7 @@ DESCRIPTION: (defprim :random-float (:number)) (defprim :random-xcor ()) (defprim :random-ycor ()) -(defprim :round ()) +(defprim :round (t)) (defprim :reset-ticks ()) (defprim :lt (:number)) (defprim :rt (:number)) diff --git a/src/main/transpile.lisp b/src/main/transpile.lisp index 3feedc2..c2a2087 100644 --- a/src/main/transpile.lisp +++ b/src/main/transpile.lisp @@ -169,6 +169,7 @@ DESCRIPTION: (defsimpleprim :random-float :reporter clnl-nvm:random-float) (defsimpleprim :random-xcor :reporter clnl-nvm:random-xcor) (defsimpleprim :random-ycor :reporter clnl-nvm:random-ycor) +(defprim :round :reporter (lambda (n) `(ffloor (+ ,n 0.5d0)))) (defsimpleprim :rt :command clnl-nvm:turn-right) (defsimpleprim :set :command cl:setf) (defsimpleprim :set-default-shape :command clnl-nvm:set-default-shape) diff --git a/src/test/simpletests.lisp b/src/test/simpletests.lisp index 5b6294f..f4ac4f9 100644 --- a/src/test/simpletests.lisp +++ b/src/test/simpletests.lisp @@ -240,3 +240,13 @@ (defsimplecommandtest "set-default-shapes 1" "crt 10 set-default-shape turtles \"sheep\" crt 10" "F0B80936630E8B597CB1088493E3765B5B4A2137") + +(defreportertestwithsetup "round 1" "crt 10" "[ round random-float 1000 ] of turtles" + "[264 551 807 834 47 117 999 259 87 963]" + "2048ED1C553B0342D5DE1302577394CD09DE88DA") + +(defsimplereportertest "round 2" "round 1.5" "2" + "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B") + +(defsimplereportertest "round 3" "round 2.5" "3" + "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B")