Scheme Scripting Cookbook:
Jon Fernquest's Open Programming Directory
Goals:
- Use higher order functions and
functional style programming as tools for creating
compact, simple, readable, provable, and reusable scripts.
- Quick partial parsing and extraction of information using
parsing combinators (sort of like regular expressions for non-regular languages)
- Fold functions with state for tree recursion applied to directory trees
and reporting on tree-like databases.
- Immitate functional style declarative GUI programming.
- Parsing and locating noun phrases relevant for a search engine query
using functional style Categorial Grammars.
- Combine the power of functional and object oriented
programming with Scheme's Tiny CLOS.
- Include introductory snippets for language teachers who want ot use Scheme as
a scripting language to find words and grammar examples in texts, i.e. Corpus Linguistics.
(These programs all run under
PLT Scheme
(aka Dr Scheme, MzScheme).
Ultimately, I want to get them to run under
Guile and Chicken with a small footprint.
Directory Tree Cumulative Disk Usage
- dirlist.scm prints out indented directory tree
with cumulative totals of megabytes (rollups) for every directory.
- filefilter.scm filters out all lines (directories) over a threshhold
amount of disk space from an indented-directory-tree file.
[output: Over 10MB:
dirlist_10.txt
, Over 100 MB:
dirlist_100.txt
are example outputs]
- readintolist1.scm copy file to new file reversing lines
Higher-Order Functions
- treetravcomb1.scm
N-ary tree traversal combinators.
(In a call to foldt (tree fold) different traversals are generated
by different combinations of list fold (foldl,foldr) and the list
constructor (cons,cons-reverse) as arguments.)
- summation1.scm
Higher order summation functions.
(based on Cousineau and Mauny, The Functional Approach to Programming" in CAML, p42-43)
- treebinua.scm binary tree upwards accumulation
; (based on Jeremy Gibbons, Generic Downwards Accumulations)
- unfold1.scm unfold examples from Oxford unfold paper,
foldt (fold tree) and foldf (fold forest),
preorder, level-order, and breadth first tree and forest traversal
- zipstrange1.scm assorted strange zip functions
Regular Expressions (using Sitaram's pregexp):
- findall1.scm find all regex matches in a string (like Python's 'findall')
- regexptest2.scm extracting HTML tags from strings
- pregexp7.scm extract all lines in a file that match a regex
and write them to another file
- pregexp9.scm search for all instances of a last name in the works
of Balzac.
Text Processing:
Awk Examples:
- awk2.scm adding line numbers to the left margin of a file
(with proper line number formatting (using string-pad))
- awk1.scm using Dr Scheme's awk macro (modelled on Scsh)
to do the same match as pregexp7.scm above in only a few lines of code
Timing a Program:
- vectormap1.scm: vector mapping functions,
timing a scalar multiplying a thousand long vector by 2
(10,000 repetitions) finding average time in milliseconds,
(note: should look at the frequency distribution seems to alternate
between taking no time and significant amount of time)
Objects and Records
-
object1.scm,
objpat1.scm,
objpat2.scm,
objpat3.scm:
Object-Oriented MzScheme programming using examples from
Falleisan and Mattheisan's book (dealing with OO Java and design patterns
in a functional style)
- object1.scm simplest possible objects using mzscheme/drscheme objects
MORE TO COME