~English

From Esolang
Jump to navigation Jump to search

~English (NOT English) is an esoteric attempt at using a natural language as a programming language. It was designed and implemented by user:AnotherTest. A statement is an English sentence. The language syntax is very loose, it is thus possible to write nonsensical sentences. Keywords always have multiple synonyms.
The are 7 types of statements in ~English:

Statement Meaning
Declaration Declares a new variable with a generic type.
Display Displays a number or a string.
Function call Calls a function.
While Provides loop functionality: loop as long as the specified condition holds.
If ... Else Conditional statement.
Stop Stops the program. Everything after "Stop" is ignored, "Stop and do something else." would thus be syntactically valid.

A user may not define functions, a set of callable functions are built-in into the language. These functions are:

  1. to number
  2. to string
  3. get input
  4. ask

Examples

Hello world

Display "Hello world!" and a newline.
Stop the program.

Example program

Create a variable named name.
Display "Enter your name: " and a newline.
Vary the value of name by call the function "ask".
Make another variable called age.
Display "Enter your age: " and a newline.
Set the value of age to call function "to number" with call another function "ask".
While the age is smaller than 0 do:
    If the age equals -100 then:
        Display "That seems highly unlikely..." and a newline.
    That's it.
    Display "Enter a valid age, " and the name.
    Display ":" and a newline.
    Set the value of age to call function "to number" with call another function "ask".
That's all.
Display "Your name is ", the name, "." and a newline.
Show "Your age is ", the age, "." and another newline.
If the name equals "World" then:
    Display "Hello World!" and a newline.
    Display another newline.
That's all.
Else, then:
    Display "Now this is no longer a 'Hello, world!' program..." and a newline.
That's all.
If the age is larger than 100 or the age equals 100 then:
    Display "You are very old." and a newline.
    Display another newline.
That's all.
Otherwise, then:
    Display "You are less than 100 years old." and a newline.
That's it.
Show "Bye!" and a newline.
Stop this program.

~English revised

~English revised is a slightly modified version of the original ~English language. It attempts to generalize certain language features, and adds a substantial amount of new ones. In particular, it provides the following additional functionality:

  • A new function call syntax is introduced. This allows making "Display" a function. The old function call syntax is no longer supported, as it didn't look very natural.
  • Programs can contain comments (notes) in addition to code.
  • Often used values can be represented by some built-in constants. For example, one can write "one" instead of 1.
  • "It" (and "its") can be used to reference the last-used variable.
  • It is possible to create user defined functions. These functions take their arguments by reference. The return statement was also introduced.
  • Sentences can end in "!" or "?".
  • Variables have been generalized to objects. What used to be a variable is now an object of type "variable". Objects can have member data, and operations may be defined on them. Duck-typing is used for this (although the variable type is a generic type).
  • Libraries can be written as shared objects or python modules. Users can create their own libraries.User-created libraries (using C/C++)
  • There is a standard library that adds support for arrays, strings and sockets. Other libraries such as maths or operating system libraries are also be integrated.

This revised version is clearly not completely compatible with the original version.

There is a C++ interpreter available on github (based on the source code of the original interpreter), but it is not yet fully implemented.

External resources