kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.61k stars 112 forks source link

Support procedural for loops #1434

Closed liangyuanpeng closed 3 months ago

liangyuanpeng commented 3 months ago

Feature Request

Is your feature request related to a problem? Please describe:

Describe the feature you'd like:

I'm using kcl to generate configuration with docker-compose for etcd cluster, i want to set a param of cluster node count and then generate a cluster, and the kcl configuration like this:

for _i:=1;i<5;i++{
        _composeService+={...}
}

This is very helpful for quickly generating a docker-compose file for a stateful service cluster! and seems like it's not support now: https://www.kcl-lang.io/docs/next/user_docs/support/faq-kcl#46-procedural-for-loop

The case2 is dynamically generate kind cluster configuration files for multiple kind nodes. https://github.com/kcl-lang/kcl/issues/1410

you can see that now i just use if count==3 / count ==5 for it (:

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

Peefy commented 3 months ago

In the current version:

If you encounter specific code implementation issues, I can provide a more detailed sample code.

liangyuanpeng commented 3 months ago

Thanks for quickly reply and i will try the range on tomorrow, seems like it's what i want!

liangyuanpeng commented 3 months ago

closing.. range is working for me.