ToString1
  (word task [?]) => "(reporter task)"

ToString2
  (word task [5]) => "(reporter task)"

ToString3
  (word task [(list 1 2 3)]) => "(reporter task)"

ToString4
  to-report foo report 0 end
  (word task [foo]) => "(reporter task)"

FunCall-Simple
  runresult [5] => 5

FunCall-With-Let
  globals [glob1]
  O> let f task [5] set glob1 runresult f
  glob1 => 5

Task-With-Args
  globals [glob1]
  O> let id task [?] set glob1 (runresult id 6)
  glob1 => 6

Call-With-Too-Many-Args-Is-Ok
  (runresult [?] 5 6 7 8) => 5

Call-With-Too-Many-Args-Is-Ok-2
  (runresult [?2] 5 6 7 8) => 6

Call-With-Too-Many-Args-Is-Ok-3
  (runresult [?1 + ?2] 5 6 7 8) => 11

Call-Task-Twice
  globals [glob1 glob2]
  O> let id task [?] set glob1 (runresult id 6) set glob2 (runresult id 7)
  glob1 => 6
  glob2 => 7

Change-Closed-Over-Var
  globals [glob1 glob2]
  O> let x 10 let addx task [? + x] set glob1 (runresult addx 6) set x 100 set glob2 (runresult addx 6)
  glob1 => 16
  glob2 => 106

Downward-Funarg
  globals [glob1]
  to-report call [fn] report (runresult fn 10) end
  O> set glob1 call task [? * ?]
  glob1 => 100

Upward-Funarg-1
  to-report foo report task [5] end
  runresult foo => 5

Upward-Funarg-2
  to-report id report task [?] end
  (runresult id 10) => 10

Upward-Funarg-3
  to-report addx [x] __let x2 x report task [? + x2] end
  (runresult addx 10 20) => 30

Upward-Funarg-4
  globals [glob1]
  to-report foo __let x 5 report task [x] end
  O> set glob1 foo
  runresult glob1 => 5

Two-Args-To-Task
  globals [glob1]
  O> set glob1 (runresult [?1 * ?2] 10 20)
  glob1 => 200

Two-Args-To-Task-In-Reverse-Order
  globals [glob1]
  O> set glob1 (runresult [?2 * ?1] 10 20)
  glob1 => 200

Two-Args-To-Task-First-Arg-Ignored
  globals [glob1]
  O> set glob1 (runresult [?2 * ?2] 10 20)
  glob1 => 400

Three-Args-To-Task
  globals [glob1]
  O> set glob1 (runresult [?1 * ?2 * ?3] 10 20 30)
  glob1 => 6000

Three-Args-To-Task-In-Reverse-Order
  globals [glob1]
  O> set glob1 (runresult [?3 * ?2 * ?1] 10 20 30)
  glob1 => 6000

Three-Args-To-Task-In-Random-Order
  globals [glob1]
  O> set glob1 (runresult [?2 * ?1 * ?3] 10 20 30)
  glob1 => 6000

Three-Args-To-Task-First-Arg-Ignored
  globals [glob1]
  O> set glob1 (runresult [?2 * ?3] 10 20 30)
  glob1 => 600

Three-Args-To-Task-Second-Arg-Ignored
  globals [glob1]
  O> set glob1 (runresult [?1 * ?3] 10 20 30)
  glob1 => 300

Three-Args-To-Task-First-And-Second-Args-Ignored
  globals [glob1]
  O> set glob1 (runresult [?3 * ?3] 10 20 30)
  glob1 => 900

Two-Args-To-Task-And-Use-Closed-Over-Var
  globals [glob1]
  O> let x 5 set glob1 (runresult task [x * ?1 * ?2] 10 20)
  glob1 => 1000

Two-Args-To-Task-And-Change-Closed-Over-Var
  globals [glob1 glob2]
  O> let x 10 let f task [x * ?1 * ?2] set glob1 (runresult f 10 20) set x 100 set glob2 (runresult f 10 20)
  glob1 => 2000
  glob2 => 20000

Inner-Task
  (runresult [?1 * (runresult [?1] 6)] 5) => 30

Inner-Task-2
  (runresult [?1 + (runresult [?1 + ?2] 2 3) + ?2] 1 4) => 10

Constant-List
  [1 2 3] => [1 2 3]

Map-Id
  map [?] [1 2 3] => [1 2 3]

Map-Id-Plus-5
  map [? + 5] [1 2 3] => [6 7 8]

Map-Two-Args
  (map [?1 + ?2] [1 2 3] [10 20 30]) => [11 22 33]

Map-Three-Args
  (map [?1 + ?2 + ?3] [1 2 3] [10 20 30] [100 200 300]) => [111 222 333]

Map-Id-With-Variable
  globals [glob1]
  O> set glob1 task [?]
  map glob1 [1 2 3] => [1 2 3]

Map-Function-Returned-From-Function
  to-report f [x] __let x2 x report task [x2 * ?] end
  map (f 5) [1 2 3] => [5 10 15]

N-Values-Id
  n-values 5 [?] => [0 1 2 3 4]

N-Values-Constant
  n-values 5 [5] => [5 5 5 5 5]

N-Values-Id-With-Variable
  globals [glob1]
  O> set glob1 task [?]
  n-values 5 glob1 => [0 1 2 3 4]

Filter-Simple
  filter [? < 3] [1 3 2] => [1 2]

Filter-Ignore-Args
  filter [1 < 3] [1 3 2] => [1 3 2]

Reduce-Tests
  reduce [?1 + ?2] [1 2 3] => 6
  reduce [?1] [1 2 3] => 1
  reduce [?2] [1 2 3] => 3
  reduce [5]  [1 2 3] => 5

Sort-By-Tests
  sort-by [?1 < ?2] [3 1 4 2] => [1 2 3 4]
  sort-by [?1 > ?2] [3 1 4 2] => [4 3 2 1]
  sort-by [length ?1 < length ?2] ["Grumpy" "Doc" "Happy"] => ["Doc" "Happy" "Grumpy"]
  sort-by [false] [1 1 1 1] => [1 1 1 1]

Combo
  map [sort-by [?1 < ?2] ?] [[2 1] [3 7 4]] => [[1 2] [3 4 7]]

CloseOverLocal1
  to-report const [x] report task [x] end
  runresult const 10 => 10

CloseOverLocal2
  to-report adder [x] report task [? + x] end
  (runresult adder 10 5) => 15

CloseOverLocalAndLet
  to-report adder [x] let y 10 report task [? + x + y] end
  (runresult (adder 100) 5) => 115

NotEnoughInputs
  runresult [?] => ERROR task expected 1 input, but only got 0

ConciseSyntax1
  map abs [1 -1 1 -1] => [1 1 1 1]

ConciseSyntax2
  to-report square [x] report x * x end
  map square [1 2 3] => [1 4 9]

ConciseSyntax3
  reduce + [1 2 3] => 6

ConciseSyntax4
  (map + [1 2 3] [10 20 30]) => [11 22 33]

ConciseSyntax5
  globals [glob1]
  O> set glob1 task [reduce + ?]
  (runresult glob1 [1 2 3]) => 6

ConciseSyntax6
  to-report plus1 [x] report x + 1 end
  map plus1 map plus1 map plus1 [1 2 3] => [4 5 6]

ConciseSyntax7
  (runresult (task +) 1 2) => 3

ConciseSyntax8
  globals [glob1]
  O> set glob1 99
  runresult task glob1 => 99

ConciseSyntax9
  globals [glob1 glob2]
  O> set glob1 99
  O> set glob2 task glob1
  runresult runresult task glob2 => 99

ConciseSyntax10
  to-report adder [n] report task [n + ?] end
  map (adder 5) [10 20 30] => [15 25 35]
  (map [(runresult ?1 ?2)] map adder [10 20 30] [1 2 3]) => [11 22 33]

ConciseSyntax11
  globals [glob1]
  O> set glob1 task 5
  runresult glob1 => 5

Flip
  to-report flip [fn] report task [(runresult fn ?2 ?1)] end
  (runresult flip task lput [1 2] 3) => [1 2 3]

Fold
  to-report fold [fn x0 xs] report reduce fn fput x0 xs end
  fold task + 0 [] => 0
  fold (task +) 0 [1 2 3] => 6

FoldAndFlip
  to-report fold [fn x0 xs] report reduce fn fput x0 xs end
  to-report flip [fn] report task [(runresult fn ?2 ?1)] end
  fold flip task fput [] [1 2 3] => [3 2 1]
  fold flip (task lput) [] [1 2 3] => [1 2 3]

is-it-or-isnt-it
  is-reporter-task? 5 => false
  is-reporter-task? task [print timer] => false
  is-reporter-task? task [timer] => true

dont-close-over-current-agent
  globals [glob1]
  O> crt 2
  O> ask turtle 0 [ set glob1 task [who] ]
  [runresult glob1] of turtle 1 => 1

recursive-factorial
  globals [glob1]
  O> set glob1 task [ ifelse-value (? = 0) [ 1 ] [ ? * (runresult glob1 (? - 1)) ] ]
  map glob1 n-values 7 [?] => [1 1 2 6 24 120 720]

recursive-fibonacci
  globals [glob1]
  O> set glob1 task [ ifelse-value (? < 2) [ 1 ] [ (runresult glob1 (? - 1)) + (runresult glob1 (? - 2)) ] ]
  map glob1 n-values 10 [?] => [1 1 2 3 5 8 13 21 34 55]

recursive-triangle-numbers-1
  globals [glob1]
  O> set glob1 task [ ifelse-value (? = 0) [ 0 ] [ ? + (runresult glob1 (? - 1)) ] ]
  map glob1 n-values 10 [?] => [0 1 3 6 10 15 21 28 36 45]

recursive-triangle-numbers-2
  globals [glob1]
  O> set glob1 task [ ifelse-value (? = 0) [ 0 ] [ (runresult glob1 (? - 1)) + ? ] ]
  map glob1 n-values 10 [?] => [0 1 3 6 10 15 21 28 36 45]

# by using __let here we're forcing a nonempty LetMap before the recursion starts - ST 2/27/11
recursive-triangle-numbers-3
  globals [glob1]
  O> __let g 0 set g task [ ifelse-value (? = 0) [ 0 ] [ (runresult g (? - 1)) + ? ] ] set glob1 g
  map glob1 n-values 10 [?] => [0 1 3 6 10 15 21 28 36 45]

empty-list-task-1
  globals [glob1]
  O> set glob1 task[[]]
  is-reporter-task? glob1 => true
  runresult glob1 => []

empty-list-task-2
  map [[]] [1 2 3] => [[] [] []]

# cheats by using recursion to define recursion.  it's a lot more
# challenging to define it without.  nonetheless, this version makes a
# nice test. - ST 4/3/11
y-combinator
  globals [glob1]
  to-report y [f] report task [(runresult f (y f) ?)] end
  to-report fact [f n] if n = 0 [ report 1 ] report n * (runresult f (n - 1)) end
  # variant 1: use fact procedure
  map [(runresult (y task fact) ?)] n-values 7 [?] => [1 1 2 6 24 120 720]
  # variant 2: use task syntax instead
  O> set glob1 y task [ifelse-value (?2 = 0) [1] [?2 * (runresult ?1 (?2 - 1))]]
  map [(runresult glob1 ?)] n-values 7 [?] => [1 1 2 6 24 120 720]

reporter-task-body-may-have-different-agent-type
  is-reporter-task? task size => true
  is-reporter-task? task pcolor => true
  is-reporter-task? task end1 => true

reporter-task-body-gets-agent-type-check
  O> __ignore task [size + link-length] => COMPILER ERROR You can't use LINK-LENGTH in a turtle context, because LINK-LENGTH is link-only.

reporter-task-closes-over-let-inside-task-of-different-agent
  globals [glob1]
  O> __let z 9 crt 1 [ set glob1 task [ z ] ]
  runresult glob1 => 9
