BeginPackage["CSM`Sexpr`"]

cons::usage = "cons[a, b] is the pair (a . b)."
car::usage  = "car[pair] is the first element of pair."
cdr::usage  = "cdr[pair] is the second element of pair."

pairQ::usage = "pairQ[e] is True if e is a pair."
atomQ::usage = "atomQ[e] is True if e is an atom."

Begin["`Private`"]

car[cons[e_, l_]] := e
cdr[cons[e_, l_]] := l

atomQ[_?AtomQ] = True   (* True for Mathematica atoms *)
atomQ[_cons] = False    (* pairs are not atoms *)
pairQ[e_] := !atomQ[e]  (* pairQ is the negation of atomQ *)

(* output formatting *)

Format[l_cons] := SequenceForm["(", Infix[l, " . "], ")"]

End[]

Protect[ car, cdr, cons, pairQ, atomQ ]

EndPackage[]
