Nite Flite Script Library 1.5 (NEW!)
March 10, 07 A collection of script libraries that implement the basic computer science structures (stacks, queues, priority queues), file operations (read, write, and append), and sorting (Bubble sort, Insertion sort, Merge sort, and Quick sort). These routines can be used and reused in lots of ways.
At the same time, these libraries also help new scripters to understand the basics of programming. The routines in this collection, while by no means "the final word" on the subject, have been written with an eye toward helping scripters to write better code that is both fast and clean.
Requirements: Mac OS X 1.4 (universal)
About these scripts...
LINKED LISTS - When I set about putting these together, I realized that most computing classes start with linked lists, then build on that to make stacks, queues, and priority queues. I thought long and hard about trying to make a linked list implementation, but AppleScript's list object already fulfills about 95% of what you could accomplish with a linked list. So I skipped linked lists and went on to..
STACKS - This implementation uses AppleScript lists to implement a standard "first-in-first-out" stack. It allows stacks of any AppleScript type that can be put into a list.
QUEUES - Also uses lists, and allows any list-friendly AppleScript data type.
PRIORITY QUEUES - This implementation keeps the priority and the cargo separately, so the cargo can be anything AppleScript will allow (including other lists or records) and the priority can be any data type that is comparable - meaning, you can say that one item is greater, equal, or lesser than another item. Lists, for example, are not comparable.
FILE HANDLERS - Contains three general-purpose handlers for writing, reading, and appending to text files. These routines are a tremendous time-saver if they fit your particular need.
SORT HANDLERS - Contains implementations of the bubble sort (both with a swap test and without), insertion sort, merge sort, and quick sort. All of these sort routines rely on AppleScript's comparable data types, so you can sort numbers or text, but not lists or records. They can be modified to allow you to use your own comparison handler that will accept lists and records, but I will leave it up to you to create your own sort comparison handlers based on your own needs.
I hope you not only get some use from these handlers, but they help you to understand some basic computer science concepts. You're free to use them in your own scripts and you need not give me credit for them. After all, they should have come with the language in the first place!
1.5 Release Notes: The big thing in this edition of NF is the addition of Martin Michel's dbeLib to the collection. DbeLib is a set of handlers for using the Database Events application. Accordingly, there are now examples of how to use dbeLib included with this edition of Nite Flite.