Comefrom0x10

From Esolang
Jump to navigation Jump to search
Comefrom0x10
Paradigm(s) Imperative
Designed by User:Julfers
Appeared in 2016
Computational class Turing complete
Major implementations Reference implementation
Influenced by ComeFrom, ComeFrom2, Come Here
File extension(s) .cf0x10

Comefrom0x10 (pronounced "come from sixteen", often abbreviated Cf0x10) is a language based on having only one flow control control statement, the comefrom statement.

Cf0x10 is higher-level than most languages with equivalent flow-control constructs such as ComeFrom2, Come Here and recent INTERCAL implementations: it introduces structured programming to the comefrom paradigm.

The reference implementation for Cf0x10 was started in October 2016[1] and released in July 2017[2].

Syntax

Cf0x10 syntactically looks similar to many modern languages. Number and string literals, for example, behave as most people would expect. Numbers are decimal floating point:

3
3.1459
"A string"
'Another string'

Unlike other esolangs, however, such as Bash, single and double quotes are interchangeable.

Line comments begin with a mesh character. There is no syntax for block comments. Because of the semantics of comefrom jumps, placement of blank lines and comments in Cf0x10 programs is often crucial:

# a comment

Cf0x10 uses named identifiers. An equals sign denotes assignment:

foo = "bar"

Identifiers must begin with an ASCII letter and may contain digits or underscores, but no uppercase letters, as those are reserved for future use. Idiomatic Cf0x10 uses snake_case.

Comefrom0x10 is procedural and line-oriented. Indentation (spaces only) denotes scope:

alice
  joe = 'me'
  joe # 'me'

joe # undefined

Space is the string concatenation operator, so these are equivalent:

'Hello ' 'world'
'Hello world'

Space is a true operator, as in CSS, not resolved at compile time as in C or Python, so this is also equivalent:

who = 'world'
'Hello ' who

Types

Comefrom0x10 has two data types, strings and numbers, plus one meta-type undefined. Cf0x10 is strongishly-typed in that some operators coerce operands to sensible values, but nonsensical operations return undefined.

'Hello ' 3.14159 # equivalent to "Hello 3.14159"
'Hello ' + 'world' # undefined

There is a proposal to add lists as a first-class type,[3] but contemporary Cf0x10 programs generally emulate lists by using strings.

Input and output

Comefrom0x10 prints any expression not captured by assignment to standard output, similar to output in PowerShell. All statements in Cf0x10 are expressions, but an expression that results in undefined prints nothing. The Hello World program, thus, is trivial:

'Hello, world!'

In the reference implementation, input may come from typical sources:

  • Command line arguments
  • Standard input
  • Files

Input is not a first-class language feature: it is achieved by libraries, such as the standard library built in to the Python reference implementation, which includes bindings so Cf0x10 programs may be embedded in Python applications and vice versa.

A Cat program may be written thus:

comefrom if stdin
stdin
stdin = ''

Comefrom

The comefrom statement is Cf0x10's only flow-control statement. It comes in the bare form:

comefrom

And the qualified form:

comefrom foo

In the qualified form, jumps are only eligible from the named block, that is, the program can only jump to comefrom foo from the block named foo.

Comefrom statements may also be conditional:

comefrom if bar

The comefrom above may receive a jump only if the value of the variable bar is truthy. The expression in a conditional comefrom may be any Cf0x10 type; coercion follows the usual rules, such as empty string being falsy.

It is allowed, and common, to combine qualified and conditional comefrom statements, as demonstrated in this Factorial program:

n = 5
acc = 1

factorial
  comefrom

  comefrom accumulate if n is 0

accumulate
  comefrom factorial
  acc = acc * n
  n = n - 1

acc

Comefrom0x10 program may jump when they encounter either a blank line or an assignment, though the semantics differ. Conditional comefroms are eligible targets of assignment only if the assignment changes the value of a variable referenced by the if clause.

Multiple eligible comefroms are not an error: Cf0x10 provides a well-defined order for where flow control continues, analogous to how comefroms are resolved in popular pub-sub frameworks:[4]

  1. Blank lines yield to any comefrom statement in inverted lexical scope
  2. When more than one comefrom is an eligible jump target in a single scope, the last wins, in source-code order
  3. Execution jumps to the current scope after jumping to eligible comefrom statements in nested scopes
  4. Nested-scope comefrom statements execute depth-first, as seen in source code indentation, where blocks that are first in the source are executed first

The documentation claims that, while perhaps confusing at first, this ordering leads to the most intuitive comefrom resolution in real programs.

Implementation

The Python reference implementation is the only known Cf0x10 interpreter. As it includes a test suite defined largely in YAML,[5] it is widely anticipated that more implementations will soon follow.

See also