til-lang / til

An easy to extend command language
56 stars 5 forks source link

Extraction syntax as iterator (for dict, list, etc.) #9

Closed dumblob closed 3 years ago

dumblob commented 3 years ago

How to iterate over dict SimpleList etc.?

Something like set d [dict (a 1)]; d | foreach k v { ... } doesn't seem to work. Maybe extraction syntax could be used to create an iterator: <$d iter> | foreach k v { ... }. I don't know. Please enlighten me :wink:.

cleberzavadniak commented 3 years ago

I already pushed to master branch a way to define "custom commands" for each type. So Dict has commandPrefix = "dict" and that means when you call any_cmd $some_dict it will first try dict.any_cmd $some_dict.

So now the idea is to use range as a data stream generator and implement list.range, dict.range commands and so on. So the syntax would be the same (range $something | foreach { ... }) but each type can implement it's own iteration logic.

(range $list | foreach is working, although it was made "manually" and this behavior is going to be ported to list.range.)