Command Values

One of the primary uses of Idio is to orchestrate commands for which the value is the exit status of the command and can be used as a boolean in (logical) expressions.

print-sleep.idio
printf "sleep 1 is %s\n" (sleep 1)

if (sleep 1) {
  printf "still tired!\n"
}

printf "done sleeping!\n"
$ idio print-sleep
sleep 1 is #t
still tired!
done sleeping!

Alternatively, replacing sleep 1 with a call to the external command false:

print-false-1.idio
printf "false is %s\n" (false)

if (false) {
  printf "untrue?\n"
} {
  printf "definitely false!\n"
}

printf "done falsifying!\n"
$ idio print-false-1

Nothing!

That’s because on the first line we ran an external command that fails and the default behaviour of Idio is much like enabling set -e in other shells. We can disable that (later!) or comment the first line out:

print-false-2.idio
;printf "false is %s\n" (false)

if (false) {
  printf "untrue?\n"
} {
  printf "definitely false!\n"
}

printf "done falsifying!\n"
$ idio print-false-2
definitely false!
done falsifying!

This time false doesn’t cause Idio to exit because it is being used in a logical expression, much like in a regular shell:

if false ; then
    echo "untrue?"
else
    echo "definitely false!"
fi

Thoughts

There’s generally little value to be had in printing the value of an external command as it can only be #t or #f (and you won’t see #f most of the time as Idio will have exited). The details of the command are kept in Job Control data.

Last built at 2024-11-21T07:11:43Z+0000 from 77077af (dev) for Idio 0.3