empty feeling sick?
coderofsalvation opened this issue · 8 comments
usage(appname)
echo $appname
run(a)
if empty? $a
help=$(usage myapp)
echo "Usage: $help" && exit
else
echo welcome
run $@
gives me:
bash: line 69: ${+-1}+1 : bad substitution
welcome
Which happens here:
empty?() {
{
local s;
[ $# -ge 1 ] && s="${1}" || s=""
}
eval "{
return \"\$(( \${$s:+1}+0 ))\"
}"
}
How about just returning ${#s} == 0 ?
Oooh, I though empty? was meant to be used with a variable for some reason. This works:
run(a)
if empty? a
# ...
If that's not the case, then your version should work.
Looking at the test, its supposed to work like this:
$ cat test/test-files/code-test.pow
...
bar()
if set? $1
echo "no argument given"
if empty? $1
echo "empty string given"
...
I will try to fix this, and my suggestion is to make it backwards-compatible with the old powscript (removing the '?').
set? makes no sense when not applied to variables though. Also, as I said in the PR, set and unset already exist as commands.
wow i literally just read your other notification (mentioning set and unset already existing) few seconds ago haha :)
Anyways, yes that totally makes sense, sorry for not having read that.
Lets leave it like this.
btw. it seems that variables in if-statement can be written as:
if -f $file
#
or
if empty a
#
Is there an idea behind a vs $a?
Sure. empty[?] works with variables, similar to unset or local, so it makes sense to me to pass names to them. -f and other flags like it work with strings.
We also already have the -z flag to ask for the empty string.
if -z $a
# ...Although all these flags seem a bit out of place in this language, hehe. We already have these forms:
if ${a:empty?}
# ...
if ${a:set?}
# ...
if ${a:unset?}
# ...
So we could remove the set? and unset? functions and keep empty[?] for the empty string, but I feel that would make things a bit (more) confusing.
agreed. Closing this issue.