diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-09-27 09:07:49 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-09-27 09:07:53 -0700 |
commit | 56e00e88789f685493002266773bad25e7740874 (patch) | |
tree | fae611e8333a9f3c71e1934b8d353d83c003a2b0 /064list.mu | |
parent | fb782b6380eb02d947851350e67747ce6126879b (diff) | |
download | mu-56e00e88789f685493002266773bad25e7740874.tar.gz |
3418 - some functions contributed by Caleb Couch
Diffstat (limited to '064list.mu')
-rw-r--r-- | 064list.mu | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/064list.mu b/064list.mu index 9216ce9b..13fc581e 100644 --- a/064list.mu +++ b/064list.mu @@ -258,6 +258,34 @@ scenario removing-from-singleton-list [ ] ] +# reverse the elements of a list +# (contributed by Caleb Couch) +def reverse list:&:list:_elem temp:&:list:_elem -> result:&:list:_elem [ + local-scope + load-ingredients + reply-unless list, temp + object:_elem <- first, list + list <- rest list + temp <- push object, temp + result <- reverse list, temp +] + +scenario reverse-list [ + run [ + local-scope + list:&:list:number <- push 1, 0 + list <- push 2, list + list <- push 3, list + stash [list:], list + list <- reverse list, 0 + stash [reversed:], list + ] + trace-should-contain [ + app: list: 3 -> 2 -> 1 + app: reversed: 1 -> 2 -> 3 + ] +] + def to-text in:&:list:_elem -> result:text [ local-scope load-ingredients |