From: Frank Duncan Date: Sun, 24 Apr 2016 02:55:38 +0000 (-0500) Subject: Prims - Implement any? X-Git-Tag: v0.1.0~45 X-Git-Url: https://code.consxy.com/gitweb/?a=commitdiff_plain;h=daa3b99095a3219506e930c7dd684bfbab4cf107;p=clnl Prims - Implement any? --- diff --git a/bin/runcmd.scala b/bin/runcmd.scala index 90a1d4d..f85ee7e 100755 --- a/bin/runcmd.scala +++ b/bin/runcmd.scala @@ -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 index f0e35e1..0000000 --- a/bin/runreporter.scala +++ /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 diff --git a/src/main/transpile.lisp b/src/main/transpile.lisp index b6e494c..d29980e 100644 --- a/src/main/transpile.lisp +++ b/src/main/transpile.lisp @@ -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) diff --git a/src/test/main.lisp b/src/test/main.lisp index a063e43..2a0da53 100644 --- a/src/test/main.lisp +++ b/src/test/main.lisp @@ -79,8 +79,27 @@ (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 diff --git a/src/test/simpletests.lisp b/src/test/simpletests.lisp index 0acddfe..ac619ca 100644 --- a/src/test/simpletests.lisp +++ b/src/test/simpletests.lisp @@ -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")