jkenda / aback

A stack-oriented language that uses Polish notation which can be reversed using the ; operator (previously |>)
0 stars 0 forks source link

pattern matching #11

Open jkenda opened 2 months ago

jkenda commented 2 months ago
(Assume 'p' is a pointer to a Point structure already pushed onto the stack)

match p with
  case 0 0 then puts "Origin point (0,0)" end
  case _ 0 then puts "Point on the x-axis" end
  case 0 _ then puts "Point on the y-axis" end
  case x y then puts "Point at coordinates (" x ", " y ")" end
end; Assume 'arr' is an array already defined

match arr with
  case 1 2 3 then puts "Array starts with 1, 2, 3" end
  case 4 5 _ then puts "Array starts with 4, 5 and has at least one more element" end
  case _ _ _ then puts "Array starts with three elements, no matter their value" end
  case else puts "Array does not match any known pattern" end
end
(Assume 'arr' is an array already defined)

match arr with
  case 1 2 3 then puts "Array starts with 1, 2, 3" end
  case 4 5 _ then puts "Array starts with 4, 5 and has at least one more element" end
  case _ _ _ then puts "Array starts with three elements, no matter their value" end
  case else puts "Array does not match any known pattern" end
end