Humble programming language

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 ...)
  • command arg1 arg2
list
(array)
[item1, item2, ...]
  1. item1
  2. item2
  3. item3
dictionary {key1: val1, key2: val2, ...}
key1

value1

key2

value2

key3

value3

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:
    1. Hello
    2. World!
(print (get-temperature) (get-wind-speed))
  • print:
    • get-temperature
    • get-wind-speed
(set arr [a,b,c])
  • set arr [ // note the "["
    1. a
    2. b
    3. 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
  • print Hello "World"

Executes command print with two string arguments "Hello" and "World".

  • set x 42
  • print x= $x

Sets the value of the variable x.

Should print out "x= 42".

  • set rect { h: 10, w: 20 }
  • set rect.h 15
  • set rect[w] 25
  • print $rect[h] x $rect.w

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
x

42

arr
  1. a
  2. b
  3. c
rect
h

10

w

20

area

(* $h $w)

  • set x 42
  • set arr [a,b,c]
rect
  • set h 10
  • set w 20
  • set area
    • multiply $h $w

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
[x]
  • add $x 1

This creates an anonymous command that returns a value increased by 1

factorial
[0]

1

[x]
  • multiply:
    • $ x
    • factorial:
      • - $x 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.

Related posts

  1. 2011-04-27 Notes from discussion on "Usefulness of inventing programming languages"
  2. 2011-04-12 Usefulness of inventing programming languages