Skip to content

Commit

Permalink
Add document to Tuple.ab (#27).
Browse files Browse the repository at this point in the history
Remove unnecessary functions from rowl1-tuple.rlc.
  • Loading branch information
nineties committed Feb 26, 2014
1 parent 766b987 commit ddfbd6d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/Boot.ab
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" Copyright (C) 2014 nineties "
" $Id: boot.ab 2014-02-26 17:08:10 nineties $ "
" $Id: boot.ab 2014-02-26 18:51:13 nineties $ "

" NB: We write comments as string literals until we define comment syntax. "

Expand Down Expand Up @@ -30,8 +30,8 @@ import Symbol
import Numeric hiding (INTEGER_WIDTH, INTEGER_MIN, INTEGER_MAX)
import Iterable
import String
import Tuple

#import Tuple
#import List
#import Array
#
Expand Down
24 changes: 19 additions & 5 deletions lib/Tuple.ab
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
# Copyright (C) 2014 nineties
# $Id: Tuple.ab 2014-02-26 17:07:32 nineties $
# $Id: Tuple.ab 2014-02-26 18:51:22 nineties $

#= Tuple =
# An n-tuple is an (ordered) collection of n objects. Tuples do not have
# functionalities as a sequence like lists or arrays. For example, you
# can't change the size of a tuple. Alternatively, tuples are very light
# and element-access is faster than other containers.
#
# The most commonly used idiom with tuples is *multivariate function*.
# You can return multiple values as a tuple and pick them up using
# pattern matching assignment.
# ----
# > f(): return (1,2,3)
# > (x, y, z): f()
# > x # => 1
# > y # => 2
# > z # => 3
# ----
trait Tuple {
.length: alias(() -> Prim.tuple_length(self))
.size: alias(() -> Prim.tuple_length(self))
.get(i): Prim.tuple_get(self, i)
.set(i, v): Prim.tuple_set(self, i, v)
# The number of elements.
.size: alias(() -> Prim.arity(self))
}

Prim.set_builtin_parent('Tuple, Trait.Tuple)
11 changes: 1 addition & 10 deletions rowl1/rowl1-tuple.rlc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; rowl - 1st generation
; Copyright (C) 2010 nineties
;
; $Id: rowl1-list.rlc 2014-02-24 16:35:59 nineties $
; $Id: rowl1-list.rlc 2014-02-26 18:50:57 nineties $
;

(import "rlvm-compile")
Expand Down Expand Up @@ -53,10 +53,6 @@
(return t)
))

(fun tp_length (t) (
(return (box (seq_size t)))
))

(fun tp_equal (t1 t2) (
(var n (seq_size t1))
(if (!= (seq_size t2) n) (return @C_FALSE))
Expand Down Expand Up @@ -138,11 +134,6 @@
))

(export fun setup_tuple (mod) (
(add_function1 mod (to_sym "tuple_length") tupleT tp_length 0)
(add_function1 mod (to_sym "tuple_size") tupleT tp_length 0)
(add_function2 mod (to_sym "tuple_equal?") tupleT tupleT tp_equal 0)
(add_function2 mod (to_sym "tuple_at") tupleT intT tp_at 0)
(add_function3 mod (to_sym "tuple_store") tupleT intT DontCare tp_store 0)
))

))

0 comments on commit ddfbd6d

Please sign in to comment.