(cond
   ((eql agentset :turtles) *turtles*)
   ((eql agentset :patches) *patches*)
-  ((and (listp agentset) (eql :agentset (car agentset))) (cdr agentset))
+  ((and (listp agentset) (eql :agentset (car agentset))) (cddr agentset))
   (t (error "Doesn't seem to be an agentset: ~A" agentset))))
 
-(defun list->agentset (list)
- (cons :agentset list))
+(defun agentset-breed (agentset)
+ (cond
+  ((eql agentset :turtles) :turtles)
+  ((eql agentset :patches) :patches)
+  ((and (listp agentset) (eql :agentset (car agentset))) (second agentset))
+  (t (error "Doesn't seem to be an agentset: ~A" agentset))))
+
+(defun list->agentset (list breed)
+ (append (list :agentset breed) list))
 
 (defun agentset-p (o)
  (or
 
   (t
    (error "Of requires an agentset or agent but got: ~A" agent-or-agentset))))
 
+(defun with (agentset fn)
+ "WITH AGENTSET FN => RESULT-AGENTSET
+
+ARGUMENTS AND VALUES:
+
+  AGENTSET: a NetLogo agentset
+  FN: a boolean function, run on each agent to determine if included
+  RESULT-AGENTSET: an agentset of valid agents
+
+DESCRIPTION:
+
+  WITH is equivalent to with in NetLogo.
+
+  Returns a new agentset containing only those agents that reported true
+  when FN is called.
+
+  See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#with"
+ (list->agentset
+  (remove-if-not
+   (lambda (agent)
+    (let ((*myself* *self*) (*self* agent)) (funcall fn)))
+   (agentset-list agentset))
+  (agentset-breed agentset)))
+
 (defun shufflerator (agentset-list)
  (let
   ((copy (copy-list agentset-list))
   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#create-turtles"
  (let
   ((new-turtles (loop :repeat n :collect (create-turtle))))
-  (when fn (ask (list->agentset new-turtles) fn))))
+  (when fn (ask (list->agentset new-turtles :turtles) fn))))
 
 (defun reset-ticks ()
  "RESET-TICKS => RESULT
 (defmethod dump-object ((o (eql t))) "true")
 (defmethod dump-object ((o (eql nil))) "false")
 
-(defmethod dump-object ((o list)) (format nil "[~{~A~^ ~}]" (mapcar #'dump-object o)))
+(defmethod dump-object ((o list))
+ (cond
+  ((agentset-p o) (format nil "(agentset, ~A ~A)" (dump-object (count o)) (string-downcase (agentset-breed o))))
+  (t (format nil "[~{~A~^ ~}]" (mapcar #'dump-object o)))))
 
 (defmethod dump-object ((o patch))
  (format nil "(patch ~A ~A)" (dump-object (patch-xcor o)) (dump-object (patch-ycor o))))
 
   #:turtles
   #:tick
   #:ticks
-  #:turn-right #:turn-left)
+  #:turn-right #:turn-left
+  #:with)
  (:documentation
   "CLNL NVM
 
 
 (defprim :count (:agentset))
 (defprim :die ())
 (defprim :display ())
-(defprim :with (:reporter-block))
+(defprim :with (:agentset :reporter-block) :infix)
 (defprim :fd (:number))
 (defprim :hatch (:number :command-block))
 ; (defprim :let (t t)) ; keeping this here, commented out, to note that it has special processing
 
 (defsimpleprim :ticks :reporter clnl-nvm:ticks)
 (defsimpleprim :turtles :reporter clnl-nvm:turtles)
 (defagentvalueprim :who)
+(defsimpleprim :with :reporter clnl-nvm:with)
 
 ; Colors
 (defmacro defcolorprim (color) `(defprim ,color :reporter (lambda () `(clnl-nvm:lookup-color ,,color))))
 
 
 (defsimplereportertest "count 3" "count patches" "9"
  "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B")
+
+(defreportertestwithsetup "with 1"
+ "crt 10 [ set color blue ] crt 10 [ set color green ]" "turtles with [ color = blue ]"
+ "(agentset, 10 turtles)"
+ "3FA51464CBF2AD493FA95A52E17768E1D8C8EFBB")
+
+(defreportertestwithsetup "with 2"
+ "crt 10 [ set color blue ] crt 10 [ set color green ]" "turtles with [ color = black ]"
+ "(agentset, 0 turtles)"
+ "3FA51464CBF2AD493FA95A52E17768E1D8C8EFBB")
+
+(defsimplereportertest "with 3" "patches with [ pcolor = green ]"
+ "(agentset, 0 patches)"
+ "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B")