Package tp :: Package client :: Package pyscheme :: Module pair
[show private | hide private]
[frames | no frames]

Module tp.client.pyscheme.pair

Implementation of pairs for Python.

Pairs are like linked lists in Python.  For historical reasons, we use
the following funny names to construct and destructure lists:

    cons(head, tail) --- constructs a ConsPair that consists of a
    head and a tail.

    car(pair) --- returns the head of a ConsPair.

    cdr(pair) --- returns the tail of a ConsPair.

Scheme's lists are built up of pair chains terminated by NIL.

The reason we use a separate factory function --- cons() --- instead
of directly using the ConsPair is because we may want the freedom to
change implementation later on.  In SICP, in fact, there's a totally
screwy implementation that uses lambdas entirely, with no real data
structure.

There are a few more convenience functions here to rapidly make these
pair structures.  For example, there's a list() function here that,
given a set of arguments, produces a pair chain.

Classes
ConsPair  
PairTests  

Function Summary
  append(*lists)
Appends all lists together.
  c_appendTwo(front, back, cont)
Appends two lists together.
  c_listMap(c_f, p, cont, allow_improper_lists)
Maps a function f across p, but in a continuation-passed style.
  cadddr(p)
  caddr(p)
  cadr(p)
  car(p)
Returns the head of the pair.
  cdddr(p)
  cddr(p)
  cdr(p)
Returns the tail of the pair.
  cons(head, rest)
Returns the concatentation of head with rest.
  isDottedPair(p)
Returns True if p refers to an improper list, where the cdr is not a pair.
  isList(p)
Returns True if p refers to a list-like structure.
  isNull(x)
  isPair(p)
  length(p)
Returns the length of p.
  list(*elements)
Does a shallow conversion of a Python list to a pair chain.
  listMap(f, p)
Maps a function f across p.
  reverse(p)
Reverses a list.
  setCarBang(pair, element)
Sets the head of the pair to the element.
  setCdrBang(pair, element)
Sets the tail of the pair to the element.
  toPythonList(pair)
Does a shallow conversion of a pair list chain to a Python list.

Variable Summary
str __license__ = 'MIT License'
list NIL = []

Function Details

append(*lists)

Appends all lists together.

c_appendTwo(front, back, cont)

Appends two lists together.  Written in continuation passing style.

c_listMap(c_f, p, cont, allow_improper_lists=False)

Maps a function f across p, but in a continuation-passed style.

'c_f' is a function that takes a 2-tuple (element, cont),
the element and the continuation.

'cont' is the continutation we apply on the mapped list.

If the optional keyword parameter 'allow_improper' is set to True,
then we'll also allow mapping across improper lists.

car(p)

Returns the head of the pair.

cdr(p)

Returns the tail of the pair.

cons(head, rest)

Returns the concatentation of head with rest.

isDottedPair(p)

Returns True if p refers to an improper list, where the cdr is
not a pair.

isList(p)

Returns True if p refers to a list-like structure.
Note: loopy structures don't qualify as lists.

length(p)

Returns the length of p.  Assumes that p is a list.

list(*elements)

Does a shallow conversion of a Python list to a pair chain.

Warning: this does have the same name as the builtin list() function
in Python.

listMap(f, p)

Maps a function f across p.

reverse(p)

Reverses a list.

setCarBang(pair, element)

Sets the head of the pair to the element.

setCdrBang(pair, element)

Sets the tail of the pair to the element.

toPythonList(pair)

Does a shallow conversion of a pair list chain to a Python list.

Variable Details

__license__

Type:
str
Value:
'MIT License'                                                          

NIL

Type:
list
Value:
[]                                                                     

Generated by Epydoc 2.1 on Fri Jan 1 08:00:27 2010 http://epydoc.sf.net