OK, turing.

<- leave blank

Wed Jul 11 14:41:56 EDT 2018

use std

const gets = {n
	if n == 0
		-> `std.Some "hello"
	;;
	-> `std.None
}

const append = {s
	if s.len < 8
		-> `std.Some std.strcat(s, " world\n")
	;;
	-> `std.None
}

const append1 = {o
	match o
	| `std.Some s: -> append(s)
	| `std.None: -> `std.None
	;;
}

const put = {o
	match o
	| `std.Some s: std.put(s)
	| `std.None:
	;;
}

const main = {
	/* 1) kind of ugly esp if more levels are needed */
	match gets(std.rand(0, 1))
	| `std.Some s:
		match append(s)
		| `std.Some s1: std.put(s1)
		| `std.None:
		;;
	| `std.None:
	;;

	/* 2) not that bad tbh but more complex cases could be worse */
	put(append1(gets(std.rand(0, 1))))

	/* 3) more readable but kind of verbose */
	var n = std.rand(0, 1)
	var input = gets(n)
	input = append1(input)
	put(input)

	/* 4) most readable, imo */
	// gets(std.rand(0, 1)) |> append1() |> put()
}