Clarity - An English Programming Language

Introduction == This document describes the Work In Progress of the design of a language called Clarity. This language is designed for those fluent in English and is meant to reduce the translational complexity of regular programming languages. When you read and write Clarity, you are writing in English with minimal syntax. The computational load on the brain of Clarity is far less than symbolically designed languages. Function Examples == The following examples show off the keywords 'the', 'of', 'named', 'taking', and 'returning': the function named double taking the number named x returning a number is add x and x done the function named square taking the number named x returning a number is multiply x and x done This is a typeless function, which is not reccomended but it does work shorthand. the function named triple taking x is multiply x and 3 done Nameless Functions == A nameless function within a function using 'over': the function named sum taking the list of numbers named xs is the number named sum then # sum is initialized to zero return over xs the function taking a number is set sum to add sum and the number done done done It also shows off nameless variables and register allocation and the use of the register 'number'. This saves on naming of things, which is a hard problem. Templates == A template is like a database table. It does not allocate much memory until you start creating from the template. $ the template named example is the string named s and the number named x and the list of numbers named ys done $ examples is a list of example done Here are two examples showing how to allocate a template using 'make': $ the-first example is make example with s as "hello" and x as 100 and ys as 1 and 2 and 3 done $ the-second-example is make example with s as "goodbyte" and x as -100 done This shows how to modify a made template: $ set the-second-example ys to a and b and c done Finally we see how to add to the list examples: $ add to examples the-first-example done $ add to examples the-second-example done The following is the example of a utility for the template example. Utilities are functions that can effect the data held in an allocated template, which is done with 'make'. $ a utility for example is the function named set-s taking the string argument x is set this s to x done done Lists == A list is a fundamental data type. $ one and two and three done (one two three) $ one and two done (one two) $ one done one $ two and four and eight and sixteen done (two four eight sixteen) Picks == Picks are groups of symbols separated by the 'or' keyword. $ the word named example-pick is one or two or three done x $ example-pick done two $ example-pick and example-pick done (three one) $ example-pick three $ example-pick one -- into vs. over ============= into xs the function taking x is add x and x done Into is destructive to the orignal list and thus does not need assignment to save the return value. $ set triples to over xs the function taking x is add x and x and x done With over the orignal list is unmodified so you have to save the return value. I would always use into although it is less functional that way. It is better for memory management. -- An example program in clarity. $ the program named example is the function named double taking the number named x returning a number is add x and x done and the function named square taking the number named x returning a number is multiply x and x done and the function named main is the number named x is 1 and double the number and square x and return x aka the number done ( (THE FUNCTION NAMED DOUBLE TAKING THE NUMBER NAMED X RETURNING A NUMBER IS ADD X AND X) (THE FUNCTION NAMED SQUARE TAKING THE NUMBER NAMED X RETURNING A NUMBER IS MULTIPLY X AND X) (THE FUNCTION NAMED MAIN IS THE NUMBER NAMED X IS 1 AND DOUBLE THE NUMBER AND SQUARE X AND RETURN X AKA THE NUMBER) ) $ run example main 4 or $ run the program main 4
Burton Samograd
2022