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

Should it be possible to deconstruct structs? #346

Open
popematt opened this issue Oct 1, 2024 · 0 comments
Open

Should it be possible to deconstruct structs? #346

popematt opened this issue Oct 1, 2024 · 0 comments
Labels
specification 1.1 Ion 1.1 specification work

Comments

@popematt
Copy link
Contributor

popematt commented Oct 1, 2024

There is no way to deconstruct a struct value or access the field names of a struct, which means that there is no way for a user to create a macro that can do something like this:

(:foo 1 2 3 { 'api-version':2, 'client-request-id': "yF8q3pZKRZ3dDfzaNy6N" })
=>
{
  foo: 1,
  bar: 2,
  baz: 3,
  'X-api-version': 2,
  'X-client-request-id': "yF8q3pZKRZ3dDfzaNy6N"
}

Hypothetically, one might be able to allow flatten to flatten a struct into pairs of field names and values, and then add some syntax to for that can bind to both the field name and the value, enabling the creation of a macro like this:

(macro foo (foo bar baz additional_properties)
       (make_struct
         ((.literal foo) foo)
         ((.literal bar) bar)
         ((.literal baz) baz)
         (.for (( [name, value] (.flatten additional_properties)) 
           (.field (make_string "X-" name) value)))

However, this is not necessarily the only or optimal solution.

@popematt popematt added the specification 1.1 Ion 1.1 specification work label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
specification 1.1 Ion 1.1 specification work
Projects
None yet
Development

No branches or pull requests

1 participant