Tim Jansen's blog


2004/07/04
Eek Code Snippets
Eek Code Snippets In order to get some more experience with Eek's look&feel, I started to reimplement small functions written in other languages. Preferable those that allow me to use Eek's advanced features. For example the famous Haskell implementation of Quicksort (intended to show how easy Haskell is, but more likely to be used as proof that the functional programming guys are.. special):
qsort []     = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
                 where
                   elts_lt_x   = [y | y <- xs, y < x]
                   elts_greq_x = [y | y <- xs, y >= x]
In Eek, using the beautiful closure filter operator '.()', a quicksort implementation could look like
class QuickSort
        static List<int> sort(List<int> list)
                int s = list[list.size / 2]
                return sort(list.(it <= s)) + sort(list.(it > s))
end
. This is an Eek version of the Binary Insertion Sort algorithm in Jeffrey Stedfast's blog (first example of the entry):
class BinarySearch
        static (int mid) sort(List a, int low, int high, int key)
		int range = low + high

		mid = (range + 1) / 2
		if (range % 2) == 1
			mid -= 1
	
		if key > a[mid]
			return sort(a, mid + 1, high, key)
		else if key < a[mid]
			return sort(a, low, mid, key)
		return
end
Nothing special here, just made the 'mid' variable a named return parameter. More examples will follow.


 

This blog is my dumping ground for thoughts and ideas about Eek. Someday Eek will be a programming language and system, somewhat comparable to Java in scope. It is my attempt to bring sanity to the world of computing.
At least I hope so. Right now it is far from being finished and I can't guarantee that it ever will be. I am still working on the specification, but I won't release anything before I got my first prototype running. The world does not need more vapourware and unusable beta-software. All publicly available information about Eek is contained in this blog. You can find the latest summary here.
This page is powered by Blogger. Isn't yours? Creative Commons License
This work is licensed under a Creative Commons License.