Version 7 of AitCS

Updated 2020-03-18 01:09:24 by Stu

AitCS - Array in the Command's Shadow

Found at: https://chiselapp.com/user/stwo/repository/aitcs

Stu 2020-03-17 Version 1.2.

Stu 2018-05-16 Created page. Version 1.0.

An Array in the Command's Shadow is an array with an associated set of commands that each provide access to or allow certain useful manipulations of the array.

An AitCS may be used where a program would normally use global or namespace variables to hold configuration, state, widget paths, temp values, etc.

Examples

# Set/Get/Variable Reference
# Save a widget and link a textvariable
aitcs new rec
aitcs new gui   
set fld preference
rec $fld Tcl
gui $fld [entry .e -textvariable [rec& $fld]]
[gui $fld] insert end /Tk
string length [rec preference]; # 6

# Get/Set  
aitcs new things
things a 3
things b [expr {[things a] + 2}]
things c [expr {[things b] * [things a]}]
things c; # 15

# Setto/Exists/Unset/Variable Reference
aitcs new fruits
fruits= apple orange pear apricot 0
if {![fruits? peach]} {
   fruits= peach 0
}                
array names [fruits&]; # {apple orange pear apricot peach}
fruits- p* a*
array names [fruits&]; # {orange}

# Get With Default
aitcs new things
things are good
things^ are ok; # good
things^ be ok; # ok

# Lappend       
aitcs new store
store this one  
store+ this two three four five
store this; # {one two three four five}

# Incr
aitcs new counters
counters cycles 0  
counters+= cycles
counters+= cycles 2
counters+= cycles -1
counters cycles; # 2

# Make Exist/Exists
aitcs new cow   
cow!
set cow(sound) moo
if {[cow? sound] && $cow(sound) eq "moo"} {
   puts "Standard English Cow"
}

# Command Reference/Variable Reference/Incr
aitcs new callback
callback count 0
after 1000 [list [callback&&]+= count]
vwait [callback& count]
callback count; # 1

# Destroy
aitcs new tmp
tmp count 5
tmp+= count -1
tmp count; # 4
set fqarr [tmp&]
info exists $fqarr; # 1
tmp---
info exists $fqarr; # 0
tmp count; # <error>