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 :slight_smile:

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!