From 76500bc57fa7d27c73905739a12520706f817534 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 4 Feb 2017 23:26:05 +0100 Subject: Parses list.squig --- list.squig | 62 ++++++++++++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'list.squig') diff --git a/list.squig b/list.squig index ea0d333..b08dafd 100644 --- a/list.squig +++ b/list.squig @@ -1,11 +1,13 @@ -new_list := ??{ - front := nil - back := nil +list_new := ??{ + x := { + front := nil + back := nil + } } list_push_front := ??(list, item){ list { - if front == nil { + if front == nil then { front = { value := item next := nil @@ -24,7 +26,7 @@ list_push_front := ??(list, item){ list_push_back := ??(list, item){ list { - if back == nil { + if back == nil then { front = { value := item next := nil @@ -44,67 +46,59 @@ list_push_back := ??(list, item){ list_pop_front := ??(list){ x := nil list { - if front == nil { + if front == nil then { throw_error("Call to 'list_pop_front' on empty list") - } + } else {} front { x = value front = next } - if front == nil { + if front == nil then { back = nil - } + } else {} } } list_pop_back := ??(list){ x := nil list { - if back == nil { + if back == nil then { throw_error("Call to 'list_pop_back' on empty list") - } + } else {} back { x = value back = prev } - if back == nil { + if back == nil then { front = nil - } + } else {} } } list_get := nil { get_helper := ??(front, idx){ - if front == nil { + if front == nil then { throw_error("Index past end of list in 'list_get'") - } + } else {} x := nil - if idx == 0 { + if idx == 0 then { front { x = value } } else { front { - found := nil - get_helper(next, idx - 1){ - found = x - } - x = found + x = get_helper(next, idx - 1) } } } list_get = ??(list, idx){ - if idx < 0 { + if idx < 0 then { throw_error("Negative index in 'list_get'") - } + } else {} x := nil list { - found := nil - get_helper(front, idx){ - found = x - } - x = found + x = get_helper(front, idx) } } } @@ -112,23 +106,23 @@ list_get := nil list_set := nil { set_helper := ??(front, idx, val){ - if front == nil { + if front == nil then { throw_error("Index past end of list in 'list_set'") - } - if idx == 0 { + } else {} + if idx == 0 then { front { value = val } } else { front { - set_helper(next, idx - 1, val){} + set_helper(next, idx - 1, val) } } } list_set = ??(list, idx, val){ - if idx < 0 { + if idx < 0 then { throw_error("Negative index in 'list_set'") - } + } else {} list { set_helper(front, idx, val) } -- cgit v1.2.3-54-g00ecf