turbo-editors/turbo-moonbitpublic Fork 0
ded61deede2aab942065647372984c8d3179037b
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-moonbit.git
git clone ssh://git@rickub.com/turbo-editors/turbo-moonbit.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

main.mbt · 37 lines · 1.1 KBMoonBit Blame HistoryRaw
📦 Turbo MoonBit cc1f595 k33g yesterday1///|
2/// Measures a handful of shapes and prints what it found.
3///
4/// Run it from the project root with `moon run cmd/main`, or from the
5/// editor's MoonBit menu with **Run** and `cmd/main`.
6fn main {
7 let circles = [
8 @shapes.Circle::{ radius: 1.0, },
9 @shapes.Circle::{ radius: 2.5, },
10 @shapes.Circle::{ radius: 0.5, },
11 ]
12 let rects = [
13 @shapes.Rect::{ width: 3.0, height: 4.0, },
14 @shapes.Rect::{ width: 1.5, height: 1.5, },
15 ]
16 report("circles", circles)
17 report("rectangles", rects)
18 report("nothing at all", ([] : Array[@shapes.Circle]))
19}
20
21///|
22/// report prints the total and the largest of a list, and says so plainly when
23/// the list is empty rather than letting the error escape.
24fn[T : @shapes.Area + Show] report(what : String, shapes : Array[T]) -> Unit {
25 println(" \{what} ")
26 try {
27 let sum = @shapes.total(shapes)
28 println(" total area: \{sum}")
29 } catch {
30 @shapes.NoShapes => println(" no shapes were given")
31 }
32 match @shapes.largest(shapes) {
33 Some(shape) => println(" largest: \{shape}")
34 None => println(" largest: none")
35 }
36 println("")
37}