Skip to content

Frequently Asked Questions, Tips and Tricks

Brent Yorgey edited this page Aug 22, 2023 · 6 revisions

Why do the colors not show properly for me?

If you only see basic colors on the map, 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. 😉

You may also want to try a different terminal application for playing Swarm. See Terminal settings for recommendations.

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 : 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 }

Why can't I run "somefile.sw"; f where f is defined in somefile.sw?

No good reason, this is a known issue and will be fixed at some point! For now, you simply have to run "somefile.sw" first, then run f as a separate REPL input.