about summary refs log tree commit diff stats
path: root/archive/2.vm/static-dispatch.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-07-27 16:01:55 -0700
committerKartik Agaram <vc@akkartik.com>2019-07-27 17:47:59 -0700
commit6e1eeeebfb453fa7c871869c19375ce60fbd7413 (patch)
tree539c4a3fdf1756ae79770d5c4aaf6366f1d1525e /archive/2.vm/static-dispatch.mu
parent8846a7f85cc04b77b2fe8a67b6d317723437b00c (diff)
downloadmu-6e1eeeebfb453fa7c871869c19375ce60fbd7413.tar.gz
5485 - promote SubX to top-level
Diffstat (limited to 'archive/2.vm/static-dispatch.mu')
-rw-r--r--archive/2.vm/static-dispatch.mu29
1 files changed, 29 insertions, 0 deletions
diff --git a/archive/2.vm/static-dispatch.mu b/archive/2.vm/static-dispatch.mu
new file mode 100644
index 00000000..a0157d13
--- /dev/null
+++ b/archive/2.vm/static-dispatch.mu
@@ -0,0 +1,29 @@
+# Example program showing how multiple functions with the same name can
+# coexist, and how we select between them.
+#
+# Expected output:
+#   4
+#   7
+#   7
+
+def test a:num -> b:num [
+  local-scope
+  load-inputs
+  b <- add a, 1
+]
+
+def test a:num, b:num -> c:num [
+  local-scope
+  load-inputs
+  c <- add a, b
+]
+
+def main [
+  local-scope
+  a:num <- test 3  # selects single-input version
+  $print a, 10/newline
+  b:num <- test 3, 4  # selects double-input version
+  $print b, 10/newline
+  c:num <- test 3, 4, 5  # prefers double- to single-input version
+  $print c, 10/newline
+]