Logo

Programming-Idioms

  • Scheme
  • Rust
let x = items[items.len()-1];
let x = items.last().unwrap();

x is a Vec.
last() returns an Option<&T>.
(define items (list 1 2 3 4))
(define x (last items))

This runs in O(n) time since list produces a linked list.
X := Items'Last

X must be declared earlier.

New implementation...