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

Confusion about condition statement #326

Open
xxchan opened this issue May 5, 2023 · 6 comments
Open

Confusion about condition statement #326

xxchan opened this issue May 5, 2023 · 6 comments
Assignees

Comments

@xxchan
Copy link

xxchan commented May 5, 2023

Describe The Bug

a = get_env ...
b = get_env ...

if not ${a} and ${b}
  ...
else
  ...
end

gets error

Error while running duckscript: Source: Unknown Line: 36 - Unexpected 'and'

To Reproduce

Error Stack

The error stack trace

Code Sample

/// paste code here
@xxchan
Copy link
Author

xxchan commented May 5, 2023

Besides,

not false and false

gives true is a little confusing... Although I can kind of understand it.

@xxchan
Copy link
Author

xxchan commented May 5, 2023

Hmmm, but why

# Unexpected value: false
if true and ( not false )

Above is in cargo-make. Using duckscript main I have the following result:

if true and ( not false )
    echo "1"
else
    echo "2"
end
1 
2

@xxchan
Copy link
Author

xxchan commented May 5, 2023

It seems eval_condition_for_slice only support literals.. (so not cannot be used)

@xxchan xxchan changed the title Not doesn't support empty value Confusion about condition statement May 5, 2023
@sagiegurari
Copy link
Owner

sorry for the confusion, but conditions like in 'if' command are build either from

  1. variable
  2. command
  3. condition

in your case, i figure you think you have a condition, but a condition is defined by "A condition statement is made up of values, or/and keywords and '('/')' groups."
see docs at:
https://github.com/sagiegurari/duckscript/blob/master/docs/sdk.md#std__flowcontrol__If

the 'not' is not a condition keyword, its also a command:
https://github.com/sagiegurari/duckscript/blob/master/docs/sdk.md#std__Not

which i guess where the confusion is coming from.
so when you have a condition phrase, you can't use embedded commands inside since i have no idea where that command args stop and the condition phrase continues.

so you need to do

a = get_env ...
b = get_env ...
not_a = not ${a}

if ${not_a} and ${b}
  ...
else
  ...
end

@xxchan
Copy link
Author

xxchan commented May 6, 2023

Yes, thanks for your answer and I’ve already fixed my problem in this way.

I don’t have strong opinion, and haven’t learned much about the design decisions of duckscript. Do you think make “not” a condition keyword can be more user-friendly?

@sagiegurari
Copy link
Owner

conditions are not part of duckscript. they are commands on their own.
it has its limitations but also extendibility where the main goal was to be super super simple lang with nothing in it just simple 1 liner syntax.
so i agree it can make things simpler, it is also not that clear where not ends and make things more complex at same time.

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

No branches or pull requests

2 participants