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 there be syntactic support for reading from a ternary expression? #2

Open
loreanvictor opened this issue Aug 4, 2023 · 0 comments
Labels
question Further information is requested

Comments

@loreanvictor
Copy link
Owner

if is now an expression, which means we have ternary expressions like this:

prompt: What is your project URL?
default:
  if: git.remote_provider
  eval: 'https://{{ git.remote_provider }}/{{ git.remote_owner }}/{{ git.remote_name }}'
  else:
    eval: Enter some url ...

However, if takes precedence over all other commands and expressions in its node, which particularly means read cannot work with ternary expressions:

read: x
if: some condition
eval: some value
else:
  eval: some other value

👆 this code will read x if some condition holds, but won't read it otherwise (will just evaluate some other value to oblivion), since if takes precedence over read.

this can be simply fixed by introducing an expression similar to if but with lower priority (right below read):

read: x
where: some condition
eval: some value
else:
  eval: some other value

👆 this code will ALWAYS read x, even without an else clause it would read it into an empty string.

this is fairly straightforward since it is a copy of if rule, however it requires further contemplation of whether it is worth adding to syntax complexity for the convenience of read command (and only read command).

Pros

  • Convenient reads with ternary expressions
  • ??

Cons

  • In a lot of cases, if and where will be interchangeable, i.e. two ways to do the same thing, which increases difficulty of reading recipe code.
  • In cases that they are not, it might be confusing.
  • Potential clash with this proposal. This is not a case of actual syntax ambiguity, since where would have lower priority to copy/update/remove (and other such commands). However it might result in increased difficulty of reading recipe code.
  • ??

This should be further contemplated. For now, I will add the code and tests for the where rule, without adding it to the standard ruleset (should it be a parametrised if rule instead?)

@loreanvictor loreanvictor added the question Further information is requested label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant