Lecture overview -- Keyboard shortcut: 'u'  Previous page: Practical list construction -- Keyboard shortcut: 'p'  Next page: Association lists -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 1 - Page 15 : 49
Programming Paradigms
Introduction to Functional Programming in Scheme
List functions

There exists a number of important List functions in Scheme, and we often write other such functions ourselves

We will here take a look at some of the most important list functions, as defined by the language itself. You are encouraged to read about them in the Scheme Report, to which we make a reference below.

  • (null? lst)     A predicate that returns whether lst is empty

  • (list? lst)     A predicate that returns whether lst is a proper list

  • (length lst)     Returns the number of elements in a proper list lst

  • (append lst1 lst2)     Concatenates the elements of two or more lists

  • (reverse lst)     Returns the elements in lst in reverse order

  • (list-ref lst k)     Accesses element number k of the list lst

It should be noticed that the first element is designated as element number 0. Thus (list-ref '(a b c) 1) returns b

  • (list-tail lst k)     Returns the k'th tail of the list lst

  • And many more

 

Lists are passed by reference to the functions that manipulate them