简体   繁体   中英

ST4 iterate a list with an index

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.

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>]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM