Skip to content

Frequently Asked Questions, Tips and Tricks

Ondřej Šebek edited this page Oct 1, 2022 · 6 revisions

Why do the colors not show properly for me?

If you only see basic colors, you probably have the TERM environment variable set to the default xterm:

echo $TERM  # prints "xterm"

Swarm uses 8-bit colors, so you need to set:

export TERM=xterm-256color
# or to set the env variable at future shell starts
echo 'export TERM=xterm-256color' >> ~/.bashrc

This setting improves the output of many terminal applications, so you likely have this set already. 😉

How can I use a cmd bool in an if?

If you try to directly use a cmd bool (such as blocked) in an if, it doesn't work: you'll get an error like Can't unify bool and cmd bool. You have to first bind the output of the cmd bool to a variable, then test that, like so:

b <- blocked;
if b { turn back } { move }

If you find yourself doing this a lot, you can even make a custom version of if which takes a cmd bool instead of a bool:

def ifC : forall a. cmd bool -> cmd a -> cmd a -> cmd a 
  = \test. \then. \else.
    b <- test;
    if b then else
end

Now you can write

ifC blocked { turn back } { move }
Clone this wiki locally