The Pooh programming language for kids and grown ups.
11 December 2012
The pooh programming language is an educational programming language. I think this means that the language should help to overcome difficulties when one tries to learn it. Many other programming languages are full with tricky tricks that are there to save a few keystrokes while typing long programs, these aids are very powerful, but people who are not already used to thinking in complicated patterns are put off by them. Learning to program with a complicated language becomes some sort of rite for geeks, who already like complicated things; Pooh thinks that the language that a person uses is important ; it makes a person accustomed to think the way he speaks, this goes on until many people are no longer used to think in any other ways. The computer language one uses as a programmer therefore sets ones mind to thinking in geeky ways (probably only when programming?). This thought is also known as the Sapir-Whorf hypothesis ; maybe there is some truth in it with regards to computer languages. I think that a simple, yet powerful language would help here.
Availability
Currently the project is available in source form only, It is released under the BSD Three clause license; The copyright is owned by Michael Moser ( c ) 2012 Sources can be downloaded as zip archive or downloaded by the git program.
git clone https://github.com/MoserMichael/cstuff.git
The project can be build on Linux or on Windows with Cygwin. To build the program,we need the presence of bison, flex, gcc and a recent version of make.
Build and install into /usr/local/ directory
cd build
./build-pooh.sh install
Build and install into /usr/alt directory
cd build
./build-pooh.sh install INSTALL_PREFIX=/usr/alt
Documentation
The Introduction to Pooh which is not complicated. (currently still working on it :-( Here Pooh library reference which is at times short an more complicated Here are Some explanations of the design decisions should be interesting for people who like programming languages.
Features
This section is interesting for people who already know a few programming languages.
- The interpreter can produce a detailed execution trace with with the annotated values for all variables. Here is an example to run a program that computes the factorial of the number 4. !include tomd-include-0.txt
- functions: all parameters are passed as named parameters , order of parameters does not matter. Named parameters make the program much more readable.
- All values defined in a function are of local scope; if you want to access a global from a function, then you have to add the global . prefix to the variable name.
- strings, numbers, arrays and hashes are not objects, one does not have to introduce object oriented programming from the start on;
- A variable is defined when a value is assigned to a variable name;.
- The compiler forbids to reference uninitialized values (like ‘use strict’ in Perl and recently optional in Javascript); also forbidden to call of undefined functions ; forbidden to use of array or hash as scalar. I really like Perl strict mode; too much dynamic typing gets me confused.
- In arithmetic operators one can use both number and string variables (strings are converted automatically); Comparison operators - there is a set of numeric comparison operators, where strings are interpreted as numbers, and string comparison operators, where both numbers and strings are allowed and interpreted as string.
- data structures: has vectors and hash values for collections.
- A simplified model of references to values is supported.
- Does object oriented programming by prototyping (prototype based programming) ) ; access to data members via this . prefix to variable names
- the concept of closures is supported, one can have objects via closures. Non local variables references have the outer . prefix.
- the concept of co-routines / generators is supported; for loops invoke a generator thread (similar to python)
- has higher order functions like map/foldl/filter/sort Multiple return values / Parallel assignment is supported.
- Strings are can span multiple lines and can embed expressions; very similar to like HERE documents; the language has one string constant format, not twenty.
- It is possible to extend the language with shared libraries written in C.
- It is possible to include other text, so it is compiled together with the program.
- Compiler has detailed error messages. Invested quite some effort to make them clear.
Things left out:
- No exceptions. Pooh programs either succeed or fail with a very detailed stack trace, its that simple.
- No namespaces; another complication.
- No meta programming; no pre-processor madness
- No eval statement;
- Currently no regular expression parsing; I would like something with fewer arcane rules, maybe BNF grammars like REBOL; Any ideas are and suggestions are really welcomed.
- Currently no way to do unicode strings; Really Have To Fix That.
- No auto-increment operators. One feature less to explain.
All this means pooh is not strongly typed, and also not a dynamic language. Hope you are still interested ;-) Because of the simplified reference model, the language probably does not translate into efficient machine code. Don’t expect the current implementation to be fast, it is an AST walker; that’s because it is easier to do the trace output with an AST walker; also I want to add a Read-eval-print loop ( in a coming release.
Tests / examples
This table lists some example programs, they make up the test suite of the project and are run on each build.
Test name | Description |
“01-add.p” | mixing strings with numers is allowed in arithmetic operators |
“01-copy-ref.p” | with references, the := operator creates alias, left hand side refers to value returned by right hand side expression. |
01-function-call-by-ref.p | function call by reference , call by value |
01-hello-world.p | hello world |
02-fact.p | function: get factorial of a number (recursive) |
02-loop.p | loops: function computes the sum of squares over integer range |
03-int-range.p | function fills array with number range, array is the return value. |
03-matrix-mult.p | test work with two dimensional matrixes. |
03-prime-while-loop.p | array test: sieve of Eratosthenes gets all prime numbers |
03-print-array.p | array test: print all elements of array, iterate with while statement. |
03-print-table.p | iterate over table and print out values. |
03-print-table2.p | iterate over table and print out values. |
03-qsort.p | a quick sort written in pooh |
03-string-split.p | test split library function - string split into array. |
03-stringlib.p | tests string library functions |
03-table-any-kind-of-key.p | table with any kind of keys |
04-file-list.p | test listing files in directory. |
04-file-stat.p | check properties of a file |
04-multi-assign.p | test multi value assignment |
04-strace-test.p | show stack trace of deep nested function (showstack function) |
04-time.p | get current date / time; functions: localtime, gmtime, currenttime |
06-func-obj-call.p | function invokes argument callback over range of numbers; prints result as ASCII graph |
08-object-prototype-finalizer.p | test where object has a finalizer - it is called when object is freed. |
08-object-prototype-point.p | 0bject oriented programming with prototypes: point class |
08-object-prototype-stack.p | 0bject oriented programming with prototypes: stack class |
10-object-closure-point.p | Object oriented programming with closures: point class |
10-object-closure-stack.p | Object oriented programming with closures: stack class. |
11-file-pipe.p | run process and script send data to it via stdin and read stdout |
11-file-test.p | working with files |
15-thread-range.p | co-routine threads: create thread via API, thread yields a range of numbers. |
15-thread-range-1.p | create co-routine thread via api |
15-thread-range-fib.p | co-routine threads: create thread via API, thread yields sequence of fibonaci numbers. |
16-load-extension-library.p | load an extension library written in C and call exported function |
17-for-lib.p | co-routines / generators as used with for statement |
17-for-range.p | co-routines / generators as used with for statement |
17-for-range-lib.p | |
17-for-while-break-skip.p | for loop ; test keywords: break - finishing the iteration and skip - continue to next iteration. |
18-higher-order-func.p | Higher order functions fold/filter/map implemented as script functions. |
18-higher-order-func-lib.p | Higher order functions fold/filter/map - use built in library implementation. |
18-higher-order-func-lib2.p | Higher order functions fold/filter/map - use built in library implementation. |
18-sort.p | use standard library sort procedure - with callback for comparison |
18-sort-anonymous.p | use standard library sort procedure - with anonymous function as callback for comparison |
The next table lists some libraries that can be included - all written in pooh
Test name | Description |
01-complex.p | test complex number library - complex.inc |
01-matrix.p | test matrix library - matrix.inc |
02-heap.p | test heap data structure - heap.inc |
02-heap2.p | test heap data structure - heap.inc |
03-queue.p | test queue data structure - queue.inc |
03-stack.p | test stack data structure - stack.inc |
04-slist.p | test linked list data structure - slist.inc |
05-graphlist.p | test adjacency graph data structure - graphlist.inc |
05-graphmatrix.p | test adjacency matrix data structure - graphmatrix.inc |
06-graphutils.p | test graph traversal class - graphutils.inc |
So what is next ?
So far I did not test the whole concept with real clients - nobody has ever used the Pooh language in order try to teach how to program. Well, it has to start with someone ?.
The concept of passing all function parameters as named parameters maybe a consistent and readable choice, but it is probably more difficult to write the program text this way. What may help is the addition of a special editing program - an IDE (Interactive developing environment) like Eclipse but with a user interface adapted for young people. Here the program parameter names will pop up as hints, together with lots of explanations about the function and its parameters. Now that is a lot of work.
Another important direction is addition of practical parsing engine ; similar to those of REBOL or Perl 6.
In the meantime I will continue to
- Test the system under different configurations
- Add missing library functions;
- Complete the introduction text.
So maybe all we have is an eclectic set of features chosen by virtue of my personal preferences and not because of any objective and measurably better usability. Maybe that’s the way programming languages are progressing; it is hard to compare approaches so that one can make a valid generalization; no tool is going to be the best in all cases, and anyway comparison are often between apples to oranges. Well enough quetching already, lets get some work done!
And now for something completely different
The best pooh movies are here