This is a hobby project. I gather my ideas of what an ideal programming language (for me) would work like. The definition is nowhere near complete or consistent. If you have comments or suggestions send me an email.
Basic Concepts
- Humble code can be embedded and edited on a web page through a browser.
Source code is rich-text with:
- bullet-lists for listing actions,
- numbered/dash lists for listing values,
- tables for dictionaries, variable and command definitions.
A plain-text version of the language should also be available.
The main values are:
- code readability,
- language simplicity,
- implementation simplicity.
Syntax
Code Structure
plain-text | HTML | |||||||
---|---|---|---|---|---|---|---|---|
action (command call) |
(command arg1 arg2 ...) |
|
||||||
list (array) |
[item1, item2, ...] |
|
||||||
dictionary | {key1: val1, key2: val2, ...} |
|
||||||
comments (top level) |
Humble supports literate programming. All text that is at the top-most level of a file/page and is not an action, list or dictionary is treated as comment. |
|||||||
comments (inside code) |
/* multiline comment text */ |
Italic text denotes comments |
||||||
// single-line comment | // You should still start comment with "//" after executable code on the same line. |
The rule of continuing lists vertically:
- You can continue listing action arguments as a nested list. You can continue listing list items as a nested list.
- Semicolon at the end of parent line is gnored.
Code | Equivalent |
---|---|
(print Hello World!) |
|
(print (get-temperature) (get-wind-speed)) |
|
(set arr [a,b,c]) |
|
Variables and Values
Unquoted strings separated by spacing are treated as string or number values. To get a value of a variable you can use $var which is a shorthand for (value var) or even ($ var).
Code | Description |
---|---|
|
Executes command print with two string arguments "Hello" and "World". |
|
Sets the value of the variable x. Should print out "x= 42". |
|
Creates an object rect with two properties (h and w). Modifies the properties. Prints out "15 x 25", using the values of the properties. |
Namespaces
- Namespaces organize variables into groups.
- Variable names inside a namespace are unique.
- Variables from a separate namespace can be accessed by adding the name of the namespace before the name of the variable.
- Namespaces are hierarchical: a name in one namespace may point to another namespace.
- There is one global top-level namespace reserved for modules. A name in this namespace points to a module namespace.
- Modules are defined in files (or web pages). One file per module and one module per file (or webpage).
- A namespace for a variable name in source code should be clearly visible.
Dictionary notation is used to express namespaces:
- A dictionary defines a set of variables in the current namespace unless it is used as an argument or it is a command definition (see below).
Example
Code | Equivalent | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Commands
I am still working on this part. This will probably change in the future.
Functions are called "commands" in Humble. This is due to a number of reasons which I will someday explain elsewhere.
- A command consists of a number of command clauses.
(This is similar to Erlang functions.) - A command clause consists of an argument list and a value or an action list.
- The result of the last action in the command clause is returned when executing the command clause.
Code | Description | ||||||
---|---|---|---|---|---|---|---|
|
This creates an anonymous command that returns a value increased by 1 |
||||||
|
This creates a recursive command factorial. (factorial 0) always returns 1. Other calls to factorial multiply its argument with argument - 1. |
Further questions
I am still experimenting with different notations for:
- Defining commands in plain-text.
- Using patterns and guards (like Erlang) in command clauses.
- Variables, their values and references to variables.
One idea I want to try out is to express plain-text Humble code as YAML. I'm guessing that adding action notation to it would be nough.