From 9413d3737ae1c07d7ec2cad29ef3a6d50ab859a9 Mon Sep 17 00:00:00 2001 From: Frank Duncan Date: Tue, 26 Apr 2016 10:17:13 -0500 Subject: [PATCH] Prims - Implement reset-ticks, tick, ticks --- src/main/nvm/base.lisp | 1 + src/main/nvm/nvm.lisp | 49 +++++++++++++++++++++++++++++++++++++++ src/main/package.lisp | 3 +++ src/main/parse.lisp | 1 + src/main/transpile.lisp | 3 +++ src/test/simpletests.lisp | 6 +++++ 6 files changed, 63 insertions(+) diff --git a/src/main/nvm/base.lisp b/src/main/nvm/base.lisp index ddd429e..5865d66 100644 --- a/src/main/nvm/base.lisp +++ b/src/main/nvm/base.lisp @@ -8,6 +8,7 @@ (defvar *self* nil) (defvar *dimensions* nil) (defvar *topology* :torus) +(defvar *ticks* nil) (defstruct turtle who color heading xcor ycor) (defstruct patch color xcor ycor) diff --git a/src/main/nvm/nvm.lisp b/src/main/nvm/nvm.lisp index 3c2e531..f2057bd 100644 --- a/src/main/nvm/nvm.lisp +++ b/src/main/nvm/nvm.lisp @@ -264,6 +264,55 @@ DESCRIPTION: See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#create-turtles" (loop :for i :from 1 :to n :do (create-turtle))) +(defun reset-ticks () + "RESET-TICKS => RESULT + +ARGUMENTS AND VALUES: + + RESULT: undefined + +DESCRIPTION: + + Resets the tick counter to zero, sets up all plots, then updates all plots. + + See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#reset-ticks" + (setf *ticks* 0d0)) + +(defun tick () + "RESET-TICKS => RESULT + +ARGUMENTS AND VALUES: + + RESULT: undefined + +DESCRIPTION: + + Advances the tick counter by one and updates all plots. + + If the tick counter has not been started yet with reset-ticks, an error results. + + See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#tick" + + (when (not *ticks*) (error "reset-ticks must be called")) + (incf *ticks*)) + +(defun ticks () + "TICKS => CURRENT-TICKS + +ARGUMENTS AND VALUES: + + CURRENT-TICKS: A positiv double, representing the current number of ticks + +DESCRIPTION: + + Reports the current value of the tick counter. The result is always a number and never negative. + + If the tick counter has not been started yet with reset-ticks, an error results. + + See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ticks" + (when (not *ticks*) (error "reset-ticks must be called")) + *ticks*) + (defun create-world (&key dims) "CREATE-WORLD &key DIMS => RESULT diff --git a/src/main/package.lisp b/src/main/package.lisp index 36fbafa..05f9cd7 100644 --- a/src/main/package.lisp +++ b/src/main/package.lisp @@ -71,9 +71,12 @@ into an ast that can be transpiled later.")) #:die #:forward #:lookup-color + #:reset-ticks #:random-float #:show #:turtles + #:tick + #:ticks #:turn-right #:turn-left) (:documentation "CLNL NVM diff --git a/src/main/parse.lisp b/src/main/parse.lisp index 72c7edc..eeadd95 100644 --- a/src/main/parse.lisp +++ b/src/main/parse.lisp @@ -256,6 +256,7 @@ DESCRIPTION: (defprim :size ()) (defprim :stop ()) (defprim :tick ()) +(defprim :ticks ()) (defprim :turtles ()) ; colors diff --git a/src/main/transpile.lisp b/src/main/transpile.lisp index 690fa3e..9dc373f 100644 --- a/src/main/transpile.lisp +++ b/src/main/transpile.lisp @@ -143,9 +143,12 @@ DESCRIPTION: (defprim-alias :if-else :ifelse) (defsimpleprim :lt :command clnl-nvm:turn-left) (defkeywordprim :nobody) +(defsimpleprim :reset-ticks :command clnl-nvm:reset-ticks) (defsimpleprim :random-float :reporter clnl-nvm:random-float) (defsimpleprim :rt :command clnl-nvm:turn-right) (defsimpleprim :show :command clnl-nvm:show) +(defsimpleprim :tick :command clnl-nvm:tick) +(defsimpleprim :ticks :reporter clnl-nvm:ticks) (defsimpleprim :turtles :reporter clnl-nvm:turtles) ; Colors diff --git a/src/test/simpletests.lisp b/src/test/simpletests.lisp index 6a3e53f..f4d6368 100644 --- a/src/test/simpletests.lisp +++ b/src/test/simpletests.lisp @@ -143,3 +143,9 @@ (defsimplecommandtest "let 2" "let a 5 let b 6 crt (a + b)" "4ABB6822402929878AB9E5A1084B9E4AE1F01D5B") + +(defsimplecommandtest "ticks 1" "reset-ticks tick" + "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B") + +(defreportertestwithsetup "ticks 1" "reset-ticks tick tick" "ticks" "2" + "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B") -- 2.25.1