59 lines
1 KiB
Text
59 lines
1 KiB
Text
val morse_code = {
|
|
"A": ".-",
|
|
"B": "-...",
|
|
"C": "-.-.",
|
|
"D": "-..",
|
|
"E": ".",
|
|
"F": "..-.",
|
|
"G": "--.",
|
|
"H": "....",
|
|
"I": "..",
|
|
"J": ".---",
|
|
"K": "-.-",
|
|
"L": ".-..",
|
|
"M": "--",
|
|
"N": "-.",
|
|
"O": "---",
|
|
"P": ".--.",
|
|
"Q": "--.-",
|
|
"R": ".-.",
|
|
"S": "...",
|
|
"T": "-",
|
|
"U": "..-",
|
|
"V": "...-",
|
|
"W": ".--",
|
|
"X": "-..-",
|
|
"Y": "-.--",
|
|
"Z": "--..",
|
|
|
|
"0": "-----",
|
|
"1": ".----",
|
|
"2": "..---",
|
|
"3": "...--",
|
|
"4": "....-",
|
|
"5": ".....",
|
|
"6": "-....",
|
|
"7": "--...",
|
|
"8": "---..",
|
|
"9": "----.",
|
|
|
|
".": ".-.-.-",
|
|
" ": " ",
|
|
}
|
|
|
|
val conv = fn(s string) {
|
|
for[=""] i of s {
|
|
_for ~= morse_code[cp2s(ucase(s[i])); "........"]
|
|
if i < len(s): _for ~= " "
|
|
}
|
|
}
|
|
|
|
val test = fn*(s string) {
|
|
# with 2 different methods of transliteration
|
|
writeln "orig. string: ", s
|
|
writeln "morse code1 : ", conv(s)
|
|
writeln "morse code2 : ", tran(ucase(s), with=morse_code, delim=" ")
|
|
writeln()
|
|
}
|
|
|
|
test("This is a test.")
|