duckscript
duckscript copied to clipboard
Confusion about condition statement
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
Besides,
not false and false
gives true is a little confusing... Although I can kind of understand it.
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
It seems eval_condition_for_slice only support literals.. (so not cannot be used)
sorry for the confusion, but conditions like in 'if' command are build either from
- variable
- command
- 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
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?
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.