File size: 1,563 Bytes
d086025 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | // ─────────────────────────────────────────────────────────────
// basics.dgn
// Dragon language basics: variables, output, and string interpolation
// Run with: dragon basics.dgn
// ─────────────────────────────────────────────────────────────
func main() {
// Variables are dynamically typed — no keyword required.
name = "Dragon"
version = 1.0
// `showln` prints with a trailing newline, `show` prints without one.
// Backtick strings support {expr} interpolation.
showln(`Welcome to ${name} v${version}!`)
age = 5
is_awesome = True
showln("age:", age, "| awesome:", is_awesome)
// `const` values cannot be reassigned after they're set.
const GREETING = "Hello"
showln(GREETING + ", World!")
// Basic arithmetic
a = 10
b = 3
showln(`${a} + ${b} = ${a + b}`)
showln(`${a} - ${b} = ${a - b}`)
showln(`${a} * ${b} = ${a * b}`)
showln(`${a} / ${b} = ${a / b}`)
showln(`${a} % ${b} = ${a % b}`)
// format() gives you fine-grained control over output
pi = 3.14159
showln(format("Pi rounded to 2 places: {:.2f}", pi))
showln(format("Padded number: [{:>6}]", 42))
// typeof() and conversions
showln("typeof age:", typeof(age))
showln("str(age):", str(age))
showln("int(\"42\"):", int("42"))
}
main()
|