Nautical bell: Difference between revisions
Content added Content deleted
(Changed the way to build "dings".) |
(Added Wren) |
||
Line 2,095: | Line 2,095: | ||
18:30 Last dog watch, Five Bells Gone: ♫ ♫ ♪ |
18:30 Last dog watch, Five Bells Gone: ♫ ♫ ♪ |
||
⋮ |
⋮ |
||
</pre> |
|||
=={{header|Wren}}== |
|||
{{trans|Go}} |
|||
{{libheader|Wren-date}} |
|||
{{libheader|Wren-fmt}} |
|||
As Wren-cli currently has no way of telling what the local time is, we ask the user to input this when executing the script. |
|||
On my system (Ubuntu 20.04), the bell only rings once no matter how many \a's are concatenated togther, though it may be different on other systems. |
|||
<lang ecmascript>import "os" for Process |
|||
import "timer" for Timer |
|||
import "/date" for Date |
|||
import "/fmt" for Fmt |
|||
var watches = ["First", "Middle", "Morning", "Forenoon", "Afternoon", "Dog", "First"] |
|||
var args = Process.arguments |
|||
if (args.count == 0) { |
|||
System.print("Please enter current time in the format (24 hour clock): hh:mm:ss.") |
|||
return |
|||
} |
|||
var now = Date.parse(args[0], Date.isoTime) |
|||
while (true) { |
|||
var h = now.hour |
|||
var m = now.minute |
|||
var s = now.second |
|||
if ((m == 0 || m == 30) && s == 0) { |
|||
var bell = (m == 30) ? 1 : 0 |
|||
var bells = (h*2 + bell) % 8 |
|||
var watch = (h/4).floor + 1 |
|||
if (bells == 0) { |
|||
bells = 8 |
|||
watch = watch - 1 |
|||
} |
|||
var sound = "\a" * bells |
|||
var pl = (bells != 1) ? "s" : "" |
|||
var w = watches[watch] + " watch" |
|||
if (watch == 5) { |
|||
if (bells < 5) { |
|||
w = "First " + w |
|||
} else { |
|||
w = "Last " + w |
|||
} |
|||
} |
|||
Fmt.lprint("$s$02d:$02d = $d bell$s : $s", [sound, h, m, bells, pl, w]) |
|||
} |
|||
Timer.sleep(1000) |
|||
now = now.addSeconds(1) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Similar to Go example. |
|||
</pre> |
</pre> |