Pooh program example 01-copy-ref.p

Test 01-copy-ref.p

Source of programm

# with references, the := operator creates alias, left hand side refers to value returned by right hand side expression.

ff := 42 
gg := ff
println( ~msg ff )
println( ~msg gg )
ff = 43
println( ~msg ff )
println( ~msg gg )

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

aaa = []

aaa[ 1 ] = 42

aaa[ 2 ] := aaa[ 1 ]

println( ~msg aaa[ 1 ] )

println( ~msg aaa[ 2 ] )

aaa[ 1 ] = 43

println( ~msg aaa[ 1 ] )

println( ~msg aaa[ 2 ] )

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

a = 42

println( ~msg a )

b := a

println( ~msg b )

a = 43

println( ~msg a )
println( ~msg b )

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

aa = 'a'

println( ~msg aa )

bb := aa

println( ~msg bb )

aa = 'aa'

println( ~msg aa )
println( ~msg bb )








Standard output for 01-copy-ref.p

42
42
43
43
42
42
43
43
42
42
43
43
a
a
aa
aa

Trace output for 01-copy-ref.p

003|ff := 42
004|gg := ff:42
005|println( ~msg ff:42 )...
006|println( ~msg gg:-> 42 )...
007|ff = 43
008|println( ~msg ff:43 )...
009|println( ~msg gg:-> 43 )...
013|aaa = [ ] 
015|aaa[1]:42 = 42
017|aaa[2]:42 := aaa[1]:42
019|println( ~msg aaa[1]:42 )...
021|println( ~msg aaa[2]:42 )...
023|aaa[1]:43 = 43
025|println( ~msg aaa[1]:43 )...
027|println( ~msg aaa[2]:43 )...
031|a = 42
033|println( ~msg a:42 )...
035|b := a:42
037|println( ~msg b:-> 42 )...
039|a = 43
041|println( ~msg a:43 )...
042|println( ~msg b:-> 43 )...
046|aa = 'a'
048|println( ~msg aa:'a' )...
050|bb := aa:'a'
052|println( ~msg bb:-> 'a' )...
054|aa = 'aa'
056|println( ~msg aa:'aa' )...
057|println( ~msg bb:-> 'aa' )...