SOUL
|
This programming language was originally designed to be integrated with a new operating system called NOUS, where a major subset of the functionality would be given to the user, which was the U in the name. It was abandoned for many years, and then during a recent period of study of the various languages currently available—with a view to adopting something more productive than the Java I’ve been using—I decided my original idea was very much worth resurrecting. Although still a hobbyist rather than enterprise-production language at this stage, there are a few noteworthy and possibly competitive features of SOUL~
Yes, that’s right. I have been chafing at the slowness of Java after programming in C many years before. And now, after having followed the rigmarole and ceremony imposed by many popular languages, I felt it was time to use a language more aligned to my personal preferences – fast, concise, elegant, small. After reviewing my original notes and design for SOUL, I felt it was potentially much more suitable, more useful. |
Basic PremiseBeing stack-based typically means values (which may be numbers or names) are pushed onto a stack, available for operators to come along and use whatever values they require from the same stack, and possibly leave a result there. Values come off the stack (are popped) in the reverse order to how they went on. Adding two numbers with the addition operator, 2 3 add we think of 2 and then 3 sitting on top of the stack (which starts at the left) and the operation happens, leaving 5 in their place – ready to be used by the next operator. This shows the essence of a simple, concatenative approach that can be used to build much more involved operations. In a sense, such expressions can be read like a phrase from a verb-last natural language like Japanese or Arabic, and likewise this is a natural alternative to the more common infix expressions like 2 plus 3 There is also no need for parentheses or operator precedence rules, since the order of operations is never ambiguous: (2 plus 3) times 4 compared with 2 3 add 4 mul The other main feature is lists of values and operators, which can become active procedures that use the stack in the same way as single native operators. This system of quotations is also found in Lisp. [ add mul ]If this is activated and applied to a stack holding 4, 2 and 3, it will leave 20 in their place. (This example also shows how function composition can be a simple affair.) SOUL does type checking at compile-time, but procedures that we create do not require annotations. The example above has a stack-effect described as rrr → r, showing it requires 3 rational numbers and leaves one rational number – this is automatically calculated and may be reported during compilation and debugging. The format of SOUL code is free-form, line-breaks are not significant, although the inclusion of transparent commas and certain transparent words (semantic fillers) can help to make the flow more natural. |
Stack valuesThe following types of values can be placed passively on the stack, until an appropriate operator or procedure is given to make use of them.
|
Simple flow control
Operators that make loops, like repeat and the ones for arrays like forall (see below) have an implicit indexer or iota called It which increments at each iteration 0 1 2 3 ... and is available for use by the procedure being looped over. |
ConversionsIt is sometimes useful to change how a value is used, by changing its type or representation.
|
Simple assignmentAssignment with def comes from PostScript, but here is used for immutable values and quotes. The semicolon form is for variables and lists (which look like quotes but can be mutated), taking values directly off the stack.
|
Array assignmentArrays come in several kinds, explicitly allocating for each value type. The extra “dimension” allows for tuples. Indexing is zero-based.
|
Other array operations
|
Math & logic operations
|
Output
|
Stack operatorsSeveral operators are available for manipulating the top 2, 3 or 4 items on the stack; shown here in comparison with the PostScript operators (one observation with PS is the somewhat distracting use of extra values to drive the operator). Note that ideally, we will access the stack to only a few elements’ depth, while avoiding use of adhoc variables – this will make the program run extremely fast, since the fixed-depth main operation stack is held in CPU registers (if it’s full we will start using stackspace in memory).
|
CommentsThere are a few styles of commenting, some more quickly typed, visually apt, familiar or useful than others.
|
Very impressed that you’ve made it this far.
Not sure how much more I can achieve without significant investment in time.
In particular, features which require deeper study and extended development include
⇒⇒⇒ SOUL zip file (< 2Mb) |
This page © Ian James.
ian