From 64f76d7af8e06ed4447acfac3c1acdb2e26a4900 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Thu, 17 Feb 2022 19:56:44 +0000 Subject: [PATCH] Add failing test that fails under, really, all the backends. --- tests/Castile.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/Castile.md b/tests/Castile.md index d06e842..6a61753 100644 --- a/tests/Castile.md +++ b/tests/Castile.md @@ -1327,3 +1327,45 @@ is accomplished. | print(l.value); | } ? struct + +One can use this facility to implement abstract data types. + + | struct assoc { + | key: string; + | value: string; + | next: assoc|void; + | } for (singleton, update, lookup, remove) + | + | fun singleton(k: string, v: string) { + | make assoc(key:k, value:v, next:null as assoc|void) + | } + | + | fun update(k: string, v: string, a: assoc) { + | make assoc(key:k, value:v, next:a as assoc|void) + | } + | + | lookup : assoc, string -> string|void + | fun lookup(a: assoc, k: string) { + | if a.key == k { + | return a.value as string|void + | } + | n = a.next + | typecase n is void { + | return null as string|void + | } + | typecase n is assoc { + | return lookup(n, k) as string|void + | } + | } + | + | fun main() { + | a = update("1", "first", update("2", "second", singleton("3", "third"))); + | r = lookup(a, "2"); + | print("um"); + | typecase r is void { print("NOT FOUND"); } + | typecase r is string { print(r); } + | print("ya"); + | } + = um + = second + = ya