RosettaCodeData/Task/Determine-if-a-string-is-numeric/EMal/determine-if-a-string-is-numeric.emal
2025-02-27 18:35:13 -05:00

26 lines
762 B
Text

fun isNumeric ← logic by text value
try
^|So funny:
|a) we check if it's castable to a real
|b) we obtain the real 0.0
|c) conversion from real to int to get 0
|d) int can be converted to logical to get ⊥
|e) we can negate the result
|^
return not when(value.contains("."), logic!int!(real!value * 0), logic!(int!value * 0))
remedy
return false
end
end
fun main ← int by List args
if args.length æ 1
writeLine(isNumeric(args[0]))
else
writeLine("value".padEnd(8, " "), " ", "numeric")
for each text value in text["0o755", "thursday", "3.14", "0b1010", "-100", "0xff"]
writeLine(value.padEnd(8, " "), " ", isNumeric(value))
end
end
return Runtime.OK
end
exit main(Runtime.args)