(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



(* :Name: PwM`Chap03Lists` *)


(* :Book: Programming with Mathematica: An Introduction *)


(* :Author: Paul Wellin *)


(* :Summary: This package contains the functions defined in Chapter 3, Lists. *)


(* :Context: PwM`Chap03Lists` *)


(* :Package Version: 1.0 *)


(* :Copyright: Copyright 2012, Paul R Wellin *)


(* :History: Version 1.0 by Paul Wellin, Dec 2012 *)


(* :Keywords: matrix columns, lattice, Ngram *)


(* :Source: Chap03Lists.nb *)


(* :Mathematica Version: 8.0.4 *)


BeginPackage["PwM`Chap03Lists`"]


AddColumn::usage="AddColumn[mat, col, pos] inserts the column vector col to the matrix mat at position pos.";


Lattice::usage="Lattice[{{xmin, xmax}, {ymin, ymax}}] creates a two-dimensional rectangular lattice with bounds given by the integers xmin, xmax, etc.";


NGrams::usage="NGrams[text, n] splits text into overlapping lists of n words.";


Begin["`Private`"]


AddColumn[mat_,col_,pos_]/;Length[col]==Length[mat]:=Transpose[Insert[Transpose[mat],col,pos]]


Lattice[{xmin_Integer,xmax_Integer},{ymin_Integer,ymax_Integer}]:=Module[{hlines,vlines,coords},
hlines=Table[{{xmin,y},{xmax,y}},{y,ymin,ymax}];
vlines=Table[{{x,ymin},{x,ymax}},{x,xmin,xmax}];
coords=Flatten[{hlines,vlines},1];
Graphics[Line[coords]]]


NGrams[text_,n_]:=Partition[
StringSplit[text,RegularExpression["\\W+"]],n,1]


End[]


EndPackage[]



