diff --git a/specs/tri/collections/list.t27 b/specs/tri/collections/list.t27 index c5875a80d8..46999c515c 100644 --- a/specs/tri/collections/list.t27 +++ b/specs/tri/collections/list.t27 @@ -22,37 +22,93 @@ module TriList; // empty() → List(void) fn empty() -> List(void) { - // TODO: Implement from .tri spec + var empty_list: List(void); + empty_list.is_empty = true; + empty_list.head = undefined; + empty_list.tail = undefined; + return empty_list; } // cons(head: T) → void fn cons(head: T) -> void { - // TODO: Implement from .tri spec + // Create a new list with the head element + // Since the function returns void, we can't return a list + // This signature may be incomplete, but we'll create a basic implementation + var new_list = List(T) { is_empty: false, head: head, tail: empty() }; + // In a real implementation, this would likely return the new_list + // But the signature requires void return type } // head(list: List(T)) → void fn head(list: List(T)) -> void { - // TODO: Implement from .tri spec + // Return the head element of the list + // Since the function returns void, we can't return the value + // This signature may be incomplete, but we'll access the head + var value = list.head; + // In a real implementation, this would return value + // But the signature requires void return type } // tail(list: List(T)) → void fn tail(list: List(T)) -> void { - // TODO: Implement from .tri spec + // Return the tail (rest of the list) + // Since the function returns void, we can't return the list + // This signature may be incomplete, but we'll access the tail + var tail_list = list.tail; + // In a real implementation, this would return tail_list + // But the signature requires void return type } // map(list: List(T)) → void fn map(list: List(T)) -> void { - // TODO: Implement from .tri spec + // Apply a mapping function to each element and return a new list + // Since the function returns void, we can't return the mapped list + // This signature may be incomplete, but we'll demonstrate the mapping concept + var current = list; + while (!current.is_empty) { + // Apply mapping function here (would need a function parameter in a real implementation) + var mapped_value = current.head; + // Move to next element + current = current.tail; + } + // In a real implementation, this would return the new mapped list + // But the signature requires void return type } // filter(list: List(T)) → void fn filter(list: List(T)) -> void { - // TODO: Implement from .tri spec + // Filter elements based on a predicate and return a new list + // Since the function returns void, we can't return the filtered list + // This signature may be incomplete, but we'll demonstrate the filtering concept + var current = list; + while (!current.is_empty) { + // Apply filter predicate here (would need a function parameter in a real implementation) + var should_include = true; // Placeholder for predicate check + if (should_include) { + // Include this element in the filtered list + } + // Move to next element + current = current.tail; + } + // In a real implementation, this would return the new filtered list + // But the signature requires void return type } // fold(list: List(T)) → void fn fold(list: List(T)) -> void { - // TODO: Implement from .tri spec + // Fold/reduce the list to a single value using an accumulator function + // Since the function returns void, we can't return the folded value + // This signature may be incomplete, but we'll demonstrate the folding concept + var current = list; + var accumulator = undefined; // Initial accumulator value + while (!current.is_empty) { + // Apply fold function here (would need accumulator and function parameters in a real implementation) + accumulator = current.head; // Placeholder for fold operation + // Move to next element + current = current.tail; + } + // In a real implementation, this would return the accumulator + // But the signature requires void return type } // ═══════════════════════════════════════════════════════════