<\n>}>" bar(x) ::= "[:]" I'd like to use the inde" /> <\n>}>" bar(x) ::= "[:]" I'd like to use the inde" /> <\n>}>" bar(x) ::= "[:]" I'd like to use the inde"/>

ST4 iterate a list with an index

661 Views Asked by At

So I have a list that is iterated over like so:

body(foo) ::= "<foo:{it|<\n><\n><bar(it)>}>"

bar(x) ::= "[<x.key>:<x.value>]"

I'd like to use the index.

bar(x) ::= "[<i0>:<x.key>:x.value>]"

I saw that there is an <i> and <i0> index token, but I don't understand how it is used, or if it could be used to do what I want to do.

1

There are 1 best solutions below

0
Novaterata On BEST ANSWER

Ok, so the trick is to pass <i> or <i0> in if you have a function, but i is implicitly available inside an iterator:

 body(foo) ::= "<foo:{it|<\n><\n><bar(i0,it)>}>"

 bar(i,x) ::= "[<i>:<x.key>:<x.value>]"