/* Conditional structures (Rosetta code) in Picat. http://rosettacode.org/wiki/Conditional_structures """ List the conditional structures offered by a programming language. Common conditional structures are if-then-else and switch. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. % import util. % import cp. /* Picat has several different kind of conditional structures. */ main => go. go => N = 10, % "direct" test that will fail if not satisfied % N < 14, % if then elseif else end if N < 14 then println("less than 14") elseif N == 14 then println("is 14") else println("not less than 14") end, % From Prolog: (condition -> then ; else) ( N < 14 -> println("less than 14") ; println("not less than 14") ), % cond/3 println(cond(N < 14, "less than 14", "not less than 14")), % as a predicate test_pred(N), % as condition in a function's head println(test_func(N)), println(ok), % all tests ok nl. % as a predicate test_pred(N) ?=> N < 14, println("less than 14"). test_pred(N) => N >= 14, println("not less than 14"). test_func(N) = "less than 14", N < 14 => true. test_func(_N) = "not less than 14" => true.