All examplesLanguage Install Aner
A linked list of mixed values
Keep integer, String, Float64, and Bool payloads in one linked structure using Any fields and parameters.
Download .aner source// One list can hold different kinds of values; unannotated fields and inputs mean Any.
class Node {
public let value
public var next: Node?
}
class LinkedList {
var head: Node?
fn prepend(value) {
head = Node(value: value, next: head)
}
fn append(value) {
let node = Node(value: value, next: null)
if head == null {
head = node
return
}
var cursor = head
while cursor.next != null {
cursor = cursor.next
}
cursor.next = node
}
fn first() {
if head == null { return null }
return head.value
}
fn print_all() {
var cursor = head
while cursor != null {
print(cursor.value)
cursor = cursor.next
}
}
fn len() {
var count = 0
var cursor = head
while cursor != null {
count = count + 1
cursor = cursor.next
}
return count
}
}
let items = LinkedList(head: null)
items.append(10)
items.append("hello")
items.append(1.5)
items.append(true)
items.print_all()
print(items.len()) // 4
print(type_of(items.first())) // Int64
print(cast<Int64>(items.first()) + 5) // 15
Make it your experiment.
With Aner installed, save this program as examples/linkedlist_mixed.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/linkedlist_mixed.aner
aner run examples/linkedlist_mixed.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Iris and Wine are teaching datasets with their own attribution. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution