Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to pass enums in params? #872

Closed
armijnhemel opened this issue Apr 4, 2021 · 2 comments
Closed

how to pass enums in params? #872

armijnhemel opened this issue Apr 4, 2021 · 2 comments
Labels

Comments

@armijnhemel
Copy link

armijnhemel commented Apr 4, 2021

Right now I am working on a spec where there are two data structures that are identical. The only difference is that they both use a different enum (with overlapping values, so I cannot merge them). I want to use params for this, so something like:

type_a:
  params:
    - id: tag_enums
  seq:
    - id: tag
      enum: tag_enums

but this doesn't seem to work. What am I doing wrong?

@generalmimon
Copy link
Member

generalmimon commented Apr 4, 2021

The only difference is that they both use a different enum (with overlapping values, so I cannot merge them). I want to use params for this

You can't. It would be nice to be able to define a "template" type and reuse it while one of the inside field has a variable type (or variable enum, makes a little difference), but in statically-typed languages this can be done relatively easily only at compile time (unlike params, which support expressions, are evaluated at run time and there's no problem with that). So we'll need to introduce a new concept of type templates/generics (#135) into the KS language.

In principle, we need something like this: https://stackoverflow.com/a/2024351

@armijnhemel
Copy link
Author

Thanks, would indeed be good to have. In the meantime I will just have to put up with some duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants