###############################################################################
#
# scope-array.eagle --
#
# Extensible Adaptable Generalized Logic Engine (Eagle)
#
# Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: $
#
###############################################################################

source [file join [file normalize [file dirname [info script]]] prologue.eagle]

###############################################################################

runTest {test scope-1.1 {create/upvar/incr array inside proc} -setup {
  proc bar { name a } {
    set c 9
    scope create -open -clone -args $name
    if {![info exists b]} then {
      upvar 2 $a b; # caller of proc bar
      set b(1) 0
      set b(3) [list]
    }
    set b(1) [expr {$b(1) + $c}]
    set b(2) [expr {$b(1) * $c}]
    if {[llength $b(3)] > 0} then {
      set b(3) [list $b(3) $b(1) $b(2)]
    } else {
      set b(3) [list $b(1) $b(2)]
    }
    return [list 1 $b(1) 2 $b(2) 3 $b(3)]; # do not use [array get] (Mono).
    # scope close; # always implied
  }
} -body {
  set s bar_array
  list [bar $s j] [bar $s j] [bar $s j]
} -cleanup {
  catch {scope destroy $s}
  unset -nocomplain s j
  rename bar ""
} -constraints {eagle} -result {{1 9 2 81 3 {9 81}}\
{1 18 2 162 3 {{9 81} 18 162}} {1 27 2 243 3 {{{9 81} 18 162} 27 243}}}}

###############################################################################

source [file join [file normalize [file dirname [info script]]] epilogue.eagle]
