Prims - Implement any?
authorFrank Duncan <frank@kank.net>
Sun, 24 Apr 2016 02:55:38 +0000 (21:55 -0500)
committerFrank Duncan <frank@kank.net>
Sun, 24 Apr 2016 02:55:38 +0000 (21:55 -0500)
bin/runcmd.scala
bin/runreporter.scala [deleted file]
src/main/transpile.lisp
src/test/main.lisp
src/test/simpletests.lisp

index 90a1d4d25a5e16dc14311680cf3bd43410149b61..f85ee7e61541d53b07cc5ba7ca82fd924903f9c5 100755 (executable)
@@ -28,10 +28,17 @@ val workspace = HeadlessWorkspace.newInstance
 workspace.silent = true
 workspace.openFromSource(url2String("file:resources/empty.nlogo"))
 
-val commands = io.Source.stdin.getLines.mkString("\n")
+val input = io.Source.stdin.getLines.mkString("\n").split("\\@\\#\\$\\#\\@\\#\\$\\#\\@")
+val commands = input(0)
 
 workspace.mainRNG.setSeed(15)
-workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileCommands(commands, api.AgentKind.Observer))
+if(commands.length > 0) {
+  workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileCommands(commands, api.AgentKind.Observer))
+}
+if(input.length > 0) {
+  val reporter = input(1)
+  System.out.println(org.nlogo.api.Dump.logoObject(workspace.runCompiledReporter(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileReporter(reporter))))
+}
 
 workspace.world.exportWorld(new java.io.PrintWriter(System.out, true), true)
 System.out.println(org.nlogo.headless.Checksummer.calculateChecksum(workspace.world.exportWorld(_, true)))
diff --git a/bin/runreporter.scala b/bin/runreporter.scala
deleted file mode 100755 (executable)
index f0e35e1..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-exec scalas "$0" -q "$@"
-!#
-
-/***
-  logLevel := Level.Error
-
-  logLevel in Global := Level.Error
-
-  scalaVersion := "2.10.3"
-
-  libraryDependencies ++= Seq(
-    "asm" % "asm-all" % "3.3.1",
-    "org.picocontainer" % "picocontainer" % "2.13.6",
-    "org.nlogo" % "NetLogo" % "6.0.0-M3" from "http://ccl.northwestern.edu/devel/6.0.0-M3/NetLogo.jar",
-    "org.nlogo" % "NetLogoHeadless" % "6.0.0-M3" from "http://ccl.northwestern.edu/devel/6.0.0-M3/NetLogoHeadless.jar"
-  )
-*/
-
-import org.nlogo.headless.HeadlessWorkspace
-import org.nlogo.mirror
-import org.nlogo.api
-import org.nlogo.nvm
-import org.nlogo.util.Utils.url2String
-
-System.out.println("----")
-val workspace = HeadlessWorkspace.newInstance
-workspace.silent = true
-workspace.openFromSource(url2String("file:resources/empty.nlogo"))
-
-val reporter = io.Source.stdin.getLines.mkString("\n")
-
-workspace.mainRNG.setSeed(15)
-System.out.println(org.nlogo.api.Dump.logoObject(workspace.runCompiledReporter(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileReporter(reporter))))
-
-workspace.world.exportWorld(new java.io.PrintWriter(System.out, true), true)
-System.out.println(org.nlogo.headless.Checksummer.calculateChecksum(workspace.world.exportWorld(_, true)))
-workspace.dispose
index b6e494c6fb439c1b558c73277d818bb79fb0d7b8..d29980ec419a1daec9f45db4e674effc80da0c12 100644 (file)
@@ -84,6 +84,7 @@ DESCRIPTION:
 (defsimpleprim :+ :reporter cl:+)
 (defsimpleprim :* :reporter cl:*)
 (defsimpleprim :/ :reporter cl:/)
+(defprim :any? :reporter (lambda (agentset) `(> (length ,agentset) 0)))
 (defsimpleprim :ask :command clnl-nvm:ask)
 (defsimpleprim :crt :command clnl-nvm:create-turtles)
 (defsimpleprim :fd :command clnl-nvm:forward)
index a063e433621e59010c4eaaab21d48c79b3ed77b7..2a0da536da513f559384131657280564f6066c97 100644 (file)
      (funcall (intern "DUMP-OBJECT" :clnl-nvm) (clnl:run-reporter ,reporter))
      (clnl-nvm:export-world)
      (checksum-world)))
-   "bin/runreporter.scala"
-   (format nil "~A~%" ,reporter)))
+   "bin/runcmd.scala"
+   (format nil "~%@#$#@#$#@~A~%" ,reporter)))
+
+(defmacro defreportertestwithsetup (name setup reporter value checksum)
+ `(defsimpletest
+   (format nil "Reporter With Setup - ~A" ,name)
+   (lambda ()
+    (clnl:boot "resources/empty.nlogo")
+    (clnl:run-commands ,setup)
+    (and
+     (string= (funcall (intern "DUMP-OBJECT" :clnl-nvm) (clnl:run-reporter ,reporter)) ,value)
+     (checksum= ,checksum (checksum-world))))
+   (lambda ()
+    (clnl:boot "resources/empty.nlogo")
+    (clnl:run-commands ,setup)
+    (format nil "~A~%~A~A"
+     (funcall (intern "DUMP-OBJECT" :clnl-nvm) (clnl:run-reporter ,reporter))
+     (clnl-nvm:export-world)
+     (checksum-world)))
+   "bin/runcmd.scala"
+   (format nil "~A~%@#$#@#$#@~A" ,setup ,reporter)))
 
 (defmacro defviewtest (name commands checksum)
  `(defsimpletest
index 0acddfec25ae3f8cd1bb22ca3cd607f5e9841d77..ac619ca84942c3fe93c10781aed42146d5c1ec36 100644 (file)
@@ -95,3 +95,9 @@
 
 (defsimplereportertest "<= 3" "random-float 4 <= random-float 7" "false"
  "811837B74F63D10ABBC01DD59C1E7556706D9F7A")
+
+(defsimplereportertest "any? 1" "any? turtles" "false"
+ "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B")
+
+(defreportertestwithsetup "any? 2" "crt 10" "any? turtles" "true"
+ "A925E39EC022967568D238D31F70F0A375024A89")