# Creating lists in Teddy

I’d like to create a list including a bunch of numbers using array operations, but I’m not sure this is possible in Teddy. I certainly can’t figure it out at least.

I’d like a list looking like this (much longer though, so explicitly defining it is not an option)

let#A 5,5,5,5,1,1,1,1,8,8

I’ve been trying the following syntax to no avail:
let#A(0:3) 5
let#A(4:7) 1
let#A(8:9) 8

Is there a clever way to append lists?

Kind regards

Loops work:

``````Let#1 0 \$ total length
Loop#2 4
Let#A(#2+#1) 5
EndLoop
Let#1 #1+#2
Loop#2 4
Let#A(#2+#1) 1
EndLoop
Let#1 #1+#2
Loop#2 2
Let#A(#2+#1) 8
EndLoop
prt#A``````

I see that you use the prt#A command in the very end of your code. Looking at the manual, this is for printing, but where do I see the print afterwards?

I had hoped for something a bit more elegant than a bunch of loops, but I guess that’s yet another workaround you have to live with in this fairly limited language of Teddy.

Thank you very much

May be, this is a little bit better (readable): ``` dbg#2 activate Debug-Print (writes only in the input-echo; not necessary) del#aa reset / initialize (is always better) let#aa 3,4,5 ; loop#lim def(aa); endloop first values and then save the Array-dimension (works so only in a "loop"-construct) let#aa(#lim+0) 66,-2 ; loop#lim def(aa); endloop next values and then … let#aa(#lim+0) -37 ; loop#lim def(aa); endloop ```
or this : ``` dbg#2 activate Debug-Print (writes only in the input-echo; not necessary) del#aa reset / initialize (is always better) loop#lim def(aa); endloop; let#Count 3; let#val 12.0134; loop#1 #count; let#aa(#lim+#1) #val; endloop loop#lim def(aa); endloop; let#Count 2; let#val -99 ; loop#1 #count; let#aa(#lim+#1) #val; endloop loop#lim def(aa); endloop; let#Count 5; let#val +8.24 ; loop#1 #count; let#aa(#lim+#1) #val; endloop loop#1 aa ; let#tt #1+1; TXA Array-Value #(tt,2.0): #(#aa(#1),6.3) endloop```

“or this” with the remark-char “\$”:

@MRCH:
Both ragl’s method and mine show in the input-echo (activate control of input in the report browser)

prt#var -> prints entire variable in the report
prt#var(2) -> prints only index 2 of variable in the report
dbg#2 -> shows all the input to sofistik explicit (can be a pain inside a proper module e.g. sofimshc, since it shows the actual cdb input)

Btw, as far as I know there is no difference between:
loop#lim def(aa); endloop;
loop#lim aa; endloop;
I think the def() is a legacy remnant from when variable were implemented to begin with.

• Yes, “dbg#2” could lead to a big input-output. It is only in special cases usefull, but it is possible to activate only for some lines below and then switch off again (with “dbg#0”) for further lines.
• “loop#lim def(aa)” is nearly the same like “#lim aa”; only a empty/non-existent array (after “del#aa”) results in the case of “#lim aa” in an error, but not in the case of “#lim def(aa)”). If “def()” is legacy? I dont know.
• The main-advantage (imho) of the last code was only a better reading: write all allocations of one value (value and quantity) in one line, the next value in the next line and so on and so you have columns of values and quantitys.
1 Like

Didn’t know about the difference in error between aa and def(aa)

Nice one!

I am now facing a similar problem once again.
Is it really true that this is the easiest way?
It simply should be possible to use some sort of array function in order to append lists!

I’ve written the following code to append three lists, but it truly should not require more that a single line

``````+prog template urs:62.1
let#A 1,2,3,4,5,6,7
let#B 8,9
let#C 10,11,12

let#D #A(:)

loop#i 2
let#D(#i+7) #B(#i)
endloop

loop#i 3
let#D(#i+7+2) #C(#i)
endloop

prt#D

end
``````

This shouldn’t require more than the following code:

``````let#D #A(:) #B(:) #C(:)
``````

The software already mentions a very similar array operation as per the Basic Manual chapter 8.2.14 (Which doesn’t seem to work either though?)

``````LET#B #A(2:3) #A(5:6)
``````

OUTPUT: (list #B changed to #E to avoid conflicts)

``````25     LET#E #A(2:3) #A(5:6)
26     PRT#E
---- CADINT VARIABLE E               (     0) =       3.000
---- CADINT VARIABLE E               (     1) =       4.000
27
28     END``````

Somewhat shorter, but still lacking some elegance:

`Let#E #A(:)`
`Loop#1 E; EndLoop; Let#E(#1) #B(:)`
`Loop#1 E; EndLoop; Let#E(#1) #C(:)`
`prt#E`

1 Like