LetSimple
  globals [glob1]
  O> let x 5 set glob1 x
  glob1 => 5

LetWithAsk
  turtles-own [tvar]
  O> crt 5
  T> let x who  set tvar x  set tvar x
  sum [tvar] of turtles => 10

LetWithinIf
  globals [glob1]
  O> if not any? turtles [ let x 6 set glob1 x ]
  glob1 => 6

LetWithSet
  globals [glob1]
  O> let x 5 set x 6 set glob1 x
  glob1 => 6

LetWithWith
  globals [glob1]
  O> let x 5 set glob1 count patches with [pxcor = x]
  glob1 => 11

LetTwiceInDifferentBlocks
  globals [glob1]
  O> set glob1 0
  O> foreach [true false] [ ifelse ? [ let x 5 set glob1 glob1 + x ] [ let x 6 set glob1 glob1 + x ] ]
  glob1 => 11

LetInsideForeach1
  globals [glob1]
  O> set glob1 0
  O> foreach [1 2 3 4] [ let x ? set glob1 glob1 + x ]
  glob1 => 10

LetInsideForeach2
  globals [glob1]
  to f let x 0 foreach [0] [ repeat 1 [ ] set glob1 x < 5 ] end
  O> f
  glob1 => true

LetWithLet
  globals [glob1]
  O> let x 5 let y x set glob1 y
  glob1 => 5

LetImmediatelyBeforeProcedureCall
  globals [glob1]
  to foo [x] set glob1 x end
  O> let y 5 foo y
  glob1 => 5

LetInsideAsk1
  globals [glob1]
  to go ask turtles [ let x who fd 1 set glob1 glob1 + x ] end
  O> crt 10 set glob1 0
  O> set glob1 0
  O> go
  glob1 => 45

LetInsideAsk2
  globals [glob1]
  O> crt 1
  O> ask turtle 0 [ let a0 9 let a1 90 set glob1 a0 + a1 ]
  glob1 => 99

LotsAndLotsOfLets
  globals [glob1]
  O> let a0 100 let a1 1 let a2 2 let a3 3 let a4 4 let a5 5 let a6 6 let a7 7 let a8 8 let a9 9 set glob1 a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9
  glob1 => 145

LotsAndLotsOfLetsInsideAsk
  globals [glob1]
  O> crt 1
  O> ask turtle 0 [ let a0 100 let a1 1 let a2 2 let a3 3 let a4 4 let a5 5 let a6 6 let a7 7 let a8 8 let a9 9 set glob1 a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 ]
  glob1 => 145

LetInsideRecursiveProcedure1
  to-report fact [n] ifelse n = 0 [ report 1 ] [ let r fact (n - 1) report n * r ] end
  fact 5 => 120

LetInsideRecursiveProcedure2
  to foo [n] let r n if n < 5 [ foo n + 1 ] if r != n [ error "oops" ] end
  O> foo 1

LetAndTemplateVariables
  globals [glob1]
  O> set glob1 0
  O> let index 0 foreach [1 2 4] [ set glob1 glob1 + index * ? set index index + 1 ]
  glob1 => 10

AllowDuplicateNamingOfLocalVariables
  to-report a let z 6 report z end
  to-report b let z 5 report z end
  to-report f [z] report z end
  to-report g [z] report z end
  a + b + f 9 + g 10 => 30

LetInsideAskConcurrent1
  O> crt 4
  O> ask-concurrent turtles [ let x who fd 1 set xcor x ]
  any? turtles with [who != xcor] => false

LetOfVarToItself1
  O> let x x => COMPILER ERROR Nothing named X has been defined.

LetOfVarToItself2
  O> let x 1 + 2 + 3 + x => COMPILER ERROR Nothing named X has been defined.

LetOfVarToItself3
  O> let x 1 + 2 + 3 + x + 4 => COMPILER ERROR Nothing named X has been defined.

LetOfVarToItselfInsideAsk
  O> ask turtles [ let x x ] => COMPILER ERROR Nothing named X has been defined.

LetTwice
  O> let x 5 let x 6 => COMPILER ERROR There is already a local variable here called X

LetTwice2
  O> let a 5 ask patches [ let a 6 ] => COMPILER ERROR There is already a local variable here called A

LetSameNameAsCommandProcedure1
  to a end
  O> let a 5 => COMPILER ERROR There is already a procedure called A

LetSameNameAsReporterProcedure1
  to-report a end
  O> let a 5 => COMPILER ERROR There is already a procedure called A

LetSameNameAsPrimitiveCommand
  O> let fd 5 => COMPILER ERROR There is already a primitive command called FD

LetSameNameAsPrimitiveReporter1
  O> let timer 5 => COMPILER ERROR There is already a primitive reporter called TIMER

LetSameNameAsPrimitiveReporter2
  O> let sin 5 => COMPILER ERROR There is already a primitive reporter called SIN

LetShadowsLet
  O> let x 4 ask patches [ let x 0 ] => COMPILER ERROR There is already a local variable here called X

LetSameNameAsGlobal
  globals [glob1]
  O> let glob1 5 => COMPILER ERROR There is already a global variable called GLOB1

LetSameNameAsBreed
  breed [mice mouse]
  O> let mice 5 => COMPILER ERROR There is already a breed called MICE

LetSameNameAsTurtleVariable
  turtles-own [tvar]
  O> let tvar 5 => COMPILER ERROR There is already a turtle variable called TVAR

LetSameNameAsBreedVariable
  breed [mice mouse]
  mice-own [fur]
  O> let fur 5 => COMPILER ERROR There is already a MICE variable called FUR
