No matching definitions.

tur/list

stdlib/list.tur

typed singly-linked List[A] with Cons cells.

Since: Phase TC1-B

defstruct

Cons

(defstruct Cons [A])

parameterized cons cell with typed head and tail.

Since: Phase TC1

defn

tcons

(tcons [h :int t :int])

prepend a value to a typed list.

hhead element of type A
ttail list (another typed list or tnil)

A new List[A] (cons cell) with h at the front.

(tcons 1 (tcons 2 (tnil)))  ; => [1, 2]

Since: Phase TC1

defn

tcons-of

(tcons-of [A])

typed Cons[A] constructor with a typed head slot.

hhead element of type A
ttail link (carrier :int; pass another cell's pointer or 0 for tnil)

A (Cons A) value whose head field is laid out as the concrete C type for A (e.g. `double` for `:float`), with no user-side bit-cast.

(let [c (tcons-of 1.5 0)]
    (.head c))  ; => 1.5, read as a `double` field

Since: Phase TS3

defn

tnil

(tnil :int)

return an empty typed list.

0, representing the empty List[A].

(tnil)  ; => empty list

Since: Phase TC1

defn

tnil?

(tnil? [l :int] :bool)

check whether a typed list is empty.

lList[A]

true if l is the empty list, false otherwise.

(tnil? (tnil))         ; => true
  (tnil? (tcons 1 (tnil)))  ; => false

Since: Phase TC1

defn

thead

(thead [A])

return the head element of a non-empty typed list.

lCons[A]

The head element of type A.

(let [l (:: (make-struct Cons 42 (tnil)) (Cons int))]
    (thead l))  ; => 42

Since: Phase TC1

defn

ttail

(ttail [A])

return the tail carrier of a non-empty typed list.

lCons[A]

The tail list carrier.

(let [l (:: (make-struct Cons 1 (tnil)) (Cons int))]
    (ttail l))  ; => 0

Since: Phase TC1

defn

list-length

(list-length [l :int])

count the number of elements in a typed list.

lList[A]

Integer length.

(list-length (list 1 2))  ; => 2

Since: Phase TC1

defn

list-eq?

(list-eq? [l1 :int l2 :int cmp-fn])

compare two typed lists element-wise.

l1first List[A]
l2second List[A]
cmp-fncomparator fn [a :int b :int] :bool

true if both lists have the same elements in the same order.

(list-eq? (list 1) (list 1) (fn [a b] (= a b)))  ; => true

Since: Phase TC1

definstance

Eq[Cons]

(definstance Eq [Cons])

element-wise equality using the element type's Eq instance.

defmacro

list

(list [& xs])

construct a list from N values via nested tcons.

& xs -- zero or more values

The right-folded (tcons ... (tnil)) chain, typed as :int (the raw carrier that tcons/tnil produce). Suitable as input to list-length, list-eq?, and the rest of the :int-taking list API. For typed (Cons A) cells (consumable by thead/ttail), build via make-struct Cons with an explicit (:: ... (Cons A)) annotation. Note: all elements must unify to a single type. Mixing types -- e.g. (list 1 "x" 3.14) -- is a type error (TUR-E0001 on the offending element). For heterogeneous fixed-arity collections, use tuple2, tuple3, tuple4, or tuple5 instead.

(list)        ; => (tnil)
  (list 1 2 3)  ; => (tcons 1 (tcons 2 (tcons 3 (tnil))))
  ; Heterogeneous -- type error:
  ; (list 1 "x")  ; => TUR-E0001: function 'tcons' arg 1: expected int, got cstr
  ; Use tuple2 instead: (tuple2 1 "x")

Since: List literal macro

defmacro

list*

(list* [& args])

prepend values onto an existing list tail.

& args -- one or more arguments; the last is the existing tail list,
prior arguments are prepended left-to-right.

The right-folded (tcons ... tail) chain where tail is the last argument. With a single argument, returns it unchanged (identity on the tail). Note: all prefix elements must unify to the same type as the elements in the tail list (all :int at the carrier level). Mixing types triggers TUR-E0001. For heterogeneous needs, use tupleN.

(list* (tnil))                    ; => (tnil)
  (list* 1 2 (tnil))                ; => (tcons 1 (tcons 2 (tnil)))
  (list* 1 2 (list 3 4))            ; => (tcons 1 (tcons 2 (tcons 3 (tcons 4 (tnil)))))

Since: List literal macro

defn

list-head

(list-head [l :int] :int)

head element of a non-empty carrier-level list.

defn

list-tail

(list-tail [l :int] :int)

tail pointer of a non-empty carrier-level list.

defn

list-concat

(list-concat [l1 :int l2 :int] :int)

concatenate two lists.

l1first List[A]
l2second List[A]

A new list with all elements of l1 followed by all elements of l2. Returns l2 directly when l1 is empty (no allocation). Note: l1 and l2 elements must share the same type (all :int at carrier level). An empty l1 returns l2 directly (no allocation). This function is a prerequisite for unquote-splicing in list-quasiquote-plan.md; the N-ary signature should be preserved.

(list-concat (list) (list 1 2))        ; => (list 1 2)
  (list-concat (list 1 2) (list))        ; => (list 1 2)
  (list-concat (list 1 2) (list 3 4))    ; => (list 1 2 3 4)

Since: List literal macro

Internal definitions
__cons-fmap-- apply a typed thunk to every head element of a Cons list.