Skip to content

Instantly share code, notes, and snippets.

@byorgey
Created October 7, 2021 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byorgey/699f522513c69fe95e96839f5ad684f7 to your computer and use it in GitHub Desktop.
Save byorgey/699f522513c69fe95e96839f5ad684f7 to your computer and use it in GitHub Desktop.
// A convenient version of if that takes a cmd bool instead of a bool
def ifC : forall a. cmd bool -> cmd a -> cmd a -> cmd a =
\test. \thn. \els. b <- test; if b thn els
end
// Do a DFS to harvest trees to the west and north.
// Position the robot on a tree near the southeast corner of a
// forest for best effect. The robot will collect a bunch
// of trees and return to its original starting point.
// Capabilities required: recursion, lambdas, scanner
def dfs : cmd () = {
ifC (ishere "tree") {
grab;
turn west;
ifC blocked {} {move; dfs; turn east; move};
turn north;
ifC blocked {} {move; dfs; turn south; move};
} {}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment