Move

Move is a modern and simple *programming language* which can run on virtually any computer. Move is primarily aimed toward people not previously familiar with programming computers.
Here is a simple Move program which outputs "Hello John" three times: hello = ^(name){ "Hello "+name } repeat {times: 3} ^{ print hello {name: "John"} }
# How to Move Move takes a mix of concepts proven successful in other programming languages, simplifies these concepts in the context of non-computer scientists while avoiding some of the more obscure constructions. By learning to program with Move you will learn what programming is. A common misconception about programming is that you learn a language. That's not entirely false, but what takes time and effort is learning how to *design* programs. So by learning a simple but yet fully featured language like Move, you minimize the initial effort required to get up to speed and can dive into the adventure of software design much earlier, not having to spend too much time thinking about the language itself. ## Why? The first thing we must discuss is *"Why should I learn to program computers?"*. It's a very good question without a single and universally good explanation, so let's simplify the answer: **To create things**. Programming is usually a good fit for one or both of the following things: 1. Realizing ideas, like creating a website or a game. Or having the computer draw you some graphics based on some data. 2. Simplifying and speeding up otherwise tedious, repetitive work. For instance, having the computer walk through thousands of files to find certain sentences. The tricky part is that programming is by definition abstract and our brains work best with concrete stuff, like "here's a stone, move it over there". Just like writing a novel or painting a fictional picture, programming works on a level above the actual result. Say we want to make a web site which changes the color of its background according to the time of day (for instance dark colors during the night and bright colors during the day), we need to *visualize the reults* before we start working. Just as the painter visualizes her motif before drawing it. When we have a good enough picture in our head of what we want to create it's time to start programming. So, in a way we work our way from an abstract idea to a concrete result. And it's fun. Now, let's get Moving! ## Values and data A *value* is a piece of information. Something that *does not do anything* but is rather used by and passed around a program. You can think of a *value* as the coffee in your coffee cup. There are only five different types in Move. The first two types of values are *simple values*: - `5.31` — A number - `"John"` — A piece of text The other two value types are so called *compound values* — values which *hold other values*: - `[1, 2, 3]` — A list (with three number values) - `{a:1, b:2}` — An object (with two number members) *Compound types* can contain any other value, including other *compound types* which makes these little buggers a very powerful tool. The fifth kind of value is a special kind of object called *function*: - `^(a, b){ a + b }` — A function which produces the sum of two numbers ## Organizing values When you want to keep a value around there's something called a *variable*. To put a value into a variable, we make up a name for the variable, then use the *equal sign* (`=`) and finally write our value. Here we store the value `"Julia"` into a variable called `name`: name = "Julia" Later in our program we can refer to `name` and get the value `"Julia"` back. For instance, we might output the value of `name` to the screen: Julia print name As the name suggests, a *variable* can *vary*, meaning we can assign any value to a variable at any time. For example, if we want our program above to output another name, we simply assign another value to our `name` variable: name = "John" When we print `name`, "John" is displayed rather than "Julia". Pretty neat, hu?! ## Reusable programs with *functions* A *function* is a block of code which can be called (or "performed" if you will) many times. We can put commonly used code inside functions to avoid re-writing the same thing several times. *Functions* are actually just *objects* (one of the five kinds of values we looked at earlier) with the addition of some code attached to it. Here is a simple function which glues together the text "Hello " with our `name` variable: hello = ^{ "Hello "+name } Earlier we used something called `print` to output values to the screen. `print` is not magic, but just a simple *function* which knows how to display values on the screen. Let's see what happens when we print our `hello` function: [Function: hello] print hello But... What?! Well, we only printed the *function* but we never *called* it, so our code that glues together text was never run. Let's try it again, but this time we add two curly brackets at the end of `hello`. This will tell Move to *call the function*: Hello John print hello{} Functions is a very powerful tool when writing programs. When creating a function, we can specify *function arguments*, which are sorrounded by parentheses and put in between the "^" and the "{". These "arguments" are just like *variables*, but which are only available inside our function. Let's add a "title" argument to our `hello` function: hello = ^(title = "Mr."){ "Hello "+title+" "+name } When calling a function you can pass it arguments: Hello Ms. John print hello {title: "Ms."} Notice how we wrote `title = "Mr."` when we created our `hello` function. This is the *default value* of the "title" argument. Let's call our function again, but this time we don't specify the "title" argument: Hello Mr. John print hello{} See. `title` represents its *default value* ("Mr."). For simple functions like our `hello` it might become "clutterish" or generally cumbersome to write `{title: "Ms."}` every time. In these cases, there's an alternate way of calling functions: the *shorthand call-style* which gives a function's arguments *in the order they where defined when creating the function*: Hello Ms. John print hello "Ms." ... *This guide is currently work in progress and will evolve over time*
# Documentation Built-in objects and functions ## Number - *literal* → number — Numbers are created using literal numbers like `123.4` or `0xf4`. Refer to the [language reference](#language-reference) for details. - Number(value) → number — Convert a value to a number. Returns the `NaN` atom if the conversion failed. - Number.MAX\_VALUE → number — The largest positive representable number. The largest negative representable number is `-MAX_VALUE`. Read-only. - Number.MIN\_VALUE → number — The smallest positive representable number — that is, the positive number closest to zero (without actually being zero). The smallest negative representable number is `-MIN_VALUE`. Read-only. - Number.NaN → NaN — Special "not a number" value. Read-only. - Number.NEGATIVE\_INFINITY → number — Special value representing negative infinity; returned on overflow. Read-only. - Number.POSITIVE\_INFINITY → number — Special value representing infinity; returned on overflow. ### Number.prototype - toExponential(fractionDigits) → text — Returns text representing the number in exponential notation. `fractionDigits` defaults to as many digits as necessary to specify the number. - toFixed(digits=0) → text — Returns text representing the number in fixed-point notation. - toPrecision(precision) → text — Returns text representing the number to a specified precision in fixed-point or exponential notation. If `precision` is not given, this function produce the same result as the toText function. ## Object - {key1: value1, key2: value2, ..., keyN: valueN} → object — Creates a new object with zero or more value properties. - Object.create(prototype, properties) → object — Creates a new object whose prototype is the passed in parent object `prototype` and whose properties are those specified by `properties`. See also: the create function. - Object.keys(obj) → [text, ...] — Returns a list of the ownProperties of an object that are enumerable. - Object.defineProperty(obj, prop, desc) — Defines a property on an object with the given descriptor - Object.defineProperties(obj, props) — Adds own properties and/or updates the attributes of existing own properties of an object - Object.getOwnPropertyNames(obj) → [text, ...] — Returns a list of the ownProperties of an object including ones that are not enumerable. - Object.getPrototypeOf(obj) → object — Returns the prototype of an object. - Object.getOwnPropertyDescriptor(obj, property) → object — Returns an object with keys describing the description of a property (value, writable, enumerable, configurable) - Object.preventExtensions(obj) — Prevents any new properties from being added to the given object. - Object.isExtensible(obj) → true|false — Checks if Object.preventExtensions() has been called on this object. - Object.seal(obj) — Prevents code from adding or deleting properties, or changing the descriptors of any property on an object. Property values can be changed however. - Object.isSealed(obj) → true|false — Checks if Object.seal() has been called on this object. - Object.freeze(obj) — Same as Object.seal, except property values cannot be changed. - Object.isFrozen(obj) → true|false — Checks if Object.freeze() has been called on this object. ### Object.prototype - constructor → function — Specifies the function that creates an object's prototype. - toText() → text — Text representation of the object. - valueOf() → object — Returns the primitive value of the object. - hasOwnProperty(name) → true|false — Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain. - isPrototypeOf(value) → true|false — Returns a boolean indication whether the specified object is in the prototype chain of the object this method is called upon. ## Array - [value1, value2, ..., valueN] → list — Creates a list holding zero or more values. - Array(length=0) → list — Creates a list with a certain initial length. Not specifying a length is equivalent to using the list literal "`[]`". - Array.isArray(value) → true|false — Test if a value is a list or not. ### Array.prototype - length → number — Number of items in the list. - [number] → value — Access or modify the value at a specific index. - concat(list2, list3, ..., listN) → list — Returns a new array comprised of this array joined with other array(s) and/or value(s). - every(^(value, index, o) → true|false, this=this) → true|false — Returns true if every element in this array satisfies the provided testing function. - filter(^(value, index, o) → value, this=this) → list — Creates a new array with all of the elements of this array for which the provided filtering function returns true. - forEach(^(value, index, o)) — Calls a function for each element in the array. - indexOf(value, startIndex=0) → number — Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found. - lastIndexOf(value, startIndex=@length-1) → number — Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found. - join(glueText="") → text — Joins all elements of an array into text. - map(^(value, index, o) → value, this=this) → list — Creates a new array with the results of calling a provided function on every element in this array. - push(value1, ..., value1) → number — Adds one or more elements to the end of an array and returns the new length of the array. - unshift(value1, ..., value1) → number — Adds one or more elements to the front of an array and returns the new length of the array. - pop() → value — Removes the last element from an array and returns that element. - shift() → value — Removes the first element from an array and returns that element. - reduce(^(previousValue, currentValue, index, o) → value, initialValue=undefined) → value — Apply a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value. - reduceRight(^(previousValue, currentValue, index, o) → value, initialValue=undefined) → value — Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value. - reverse() → list — Reverses the order of the elements of an array — the first becomes the last, and the last becomes the first. This function does not create a new list, but modifies the calling list in place. - slice(startIndex, endIndex=@length) → — Extracts a section of an array and returns a new array. - some(^(value, index, o) → true|false) → true|false — Returns true if at least one element in this array satisfies the provided testing function. - sort(^(value1, value2) → number =undefined) → list — Sorts the elements of an array. This function does not create a new list, but modifies the calling list in place. - splice(index, howMany[, element1[, ...[, elementN]]]) → list — Adds and/or removes elements from an array. Returns the caller. ## Text *Text* is an alias for the JavaScript built-in type `String` and is the object prototype used for text values. The use of `Text` in favor for `String` is recommended but not enforced. - Text(value) → text — Text representation of `value` - Text.fromCharCode(number) → text — Text of character representing a Unicode character code. ### Text.prototype - length → number — Number of characters. - charAt(number) → text — Returns the character at the specified index. - [number] → text — Text representing the character at position `number`. - charCodeAt(number) → number — Returns a number indicating the Unicode value of the character at the given index. - concat(string2, string3, ..., stringN]) → text — Combines the text of two strings and returns a new string. Same as `string + string2 + string3 + ... stringN`. - indexOf(needle, startIndex=0) → number — Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found. - lastIndexOf(needle, startIndex=@length-1) → number — Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found. - localeCompare(other) → number — Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order. - match(regexp) → object — Used to match a regular expression against a string. - replace(text|regexp, replacement|function) → text — Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring. - search(regexp) → number — Executes the search for a match between a regular expression and a specified string. Returns the index of the regular expression inside the string. Faster than match but returns less information. - slice(startIndex, endIndex=@length-1) → text — Extracts a section of a string and returns a new string. - split(text|regexp, limit=Number.POSITIVE\_INFINITY) → [text, text, ...] — Splits text into a list of texts by separating the text into smaller chunks. - substr(startIndex, length=@length-1) → text — Returns the characters beginning at the specified location through the specified number of characters. - substring(startIndex, endIndex=@length) → text — Returns the characters in a string between two indexes in the text. - toLowerCase() → text — Returns a version of the text converted to lower case. - toUpperCase() → text — Returns a version of the text converted to upper case. - trim() → text — Trims whitespace from both ends of the string - trimRight() → text — Trims whitespace from the right side of the string - trimLeft() → text — Trims whitespace from the left side of the string ## Function - ^(arg1[=val1], arg2[=val2], ..., argN[=valN]) { body } → function — Create a function with zero or more arguments where "body" is substituted for the function's code block. ### Function.prototype - apply(this, arguments=[]) → value — Applies the function in the context (the "this" value) of a different object. Arguments can be passed as an Array object. - call(this, argument1, argument2, ..., argumentN) → value — Applies the function in the context (the "this" value) of a different object. Arguments can be passed as a succession of extra arguments. ## Date TODO ## RegExp - /pattern/flags → regexp — Create a regular expression by compiling `pattern` (unquoted text) with regards to `flags` (unquoted text). - RegExp(pattern, flags="") → regexp — Create a regular expression object by compiling `pattern` (text) with regards to `flags` which can have any combination of the following values: - **g** — global match - **i** — ignore case - **m** — Treat beginning and end characters (^ and $) as working over multiple lines (i.e., match the beginning or end of each line (delimited by \n or \r), not only the very beginning or end of the whole input string) ### RegExp.prototype - global → true|false — Whether to test the regular expression against all possible matches in a text, or only against the first. - ignoreCase → true|false — Whether to ignore case while attempting a match. - multiline → true|false — Whether or not to search in text across multiple lines. - lastIndex → number — The index at which to start the next match. - source → text — The text of the pattern. - exec(text) → list — Executes a search for a match in its text parameter. The returned list contains the matched groups as text plus it has the following properties: - index → number — The 0-based index of the match in the text. - input → text — The original input text. - test(text) → true|false — Tests for a match in its text parameter. ## Boolean - Boolean(value) → true|false
# Language reference This is a summary of the Move language and not a complete reference. Please see [the ECMA-262 specification](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf) for details. ## Value types There are five different value types in Move: numbers, text, lists, objects and functions. ### Numbers Numbers can be written in either decimal, hexadecimal or octal notation. - Decimal notation: `1234`, `5.31` or `.8` — Starts with zero or more digits (0-9), has an optional dot ("." aka "full stop") followed by zero or more digits. The regular expression used by the Move parser to interpret decimal numbers is: `/^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i` - Hexadecimal notation: `0x4d2` or `0x5` — Starts with "0x" and is followed by one or more hexadecimal digits (0-9, a-f) where the "alpha digits" (a-f) can be written in either lower case, upper case or a mix thereof. Only integers can be expressed in "hex" notation. Regular expression used by the parser: `/^0x[0-9a-f]+$/i` - Octal notation: `02322` or `0664` — Starts with "0" and is followed by one or more octal digits (0-7). Regular expression used by the parser: `/^0[0-7]+$/` - "Not a number": `NaN` — A special constant used to represent an illegal computation or a failed to-number conversion. The Number type has exactly 18437736874454810627 (that is, 264-253+3) values, representing the double- precision 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic, except that the 9007199254740990 (that is, 253-2) distinct “Not-a-Number” values of the IEEE Standard are represented in ECMAScript as a single special NaN value. Example: 1234 1234 1234 true print 1234 print 0x4d2 print 02322 print 1234 == 1234.0 ### Text Text can contain any Unicode characters and is stored as UTF-16 text. A piece of text is denoted by enclosing quotation marks (" and " or ' and ') with any text except line breaks or (same as the enclosing) quotation marks. Standard escape sequences (like "\n" and "\t") as well as Unicode escape sequences ("\u" followed by four hexadecimal digits) can be used to encode any Unicode character into the text, like line breaks. The backslash character ("\") can also be used to escape characters like an embedded quotation mark. - Text: `"John"` — A piece of text representing "John" - Text with Unicode escape sequence: `"John \u2665 Jane"` — A piece of text representing "John ♥ Jane" - Text with embedded quotation marks: `"John aka \"Johnny\""` — A piece of text representing "John aka "Johnny"" - Text with embedded quotation marks wrapped in single quotes: `'John aka "Johnny"'` — A piece of text representing "John aka "Johnny"" Text is internally represented by the `Text` object (an alias for `String`). Adding functions to the `Text` object's prototype will make that function available to any text value. Example of calling the built-in split function on a piece of text to produce a list of substrings: ["Kittens", "are", "cute"] print "Kittens are cute".split(" ") ### Lists and "arrays" A List (or Array) is a form of compound value which contains other values in a ordered sequence. Lists are composed by enclosing zero or more values in a square bracket character pair ("[" and "]"), separated by comma characters. Lists can also be created by programmatic composition. The built-in Array object's prototype is the prototype used for new lists. -  `["Kittens", "are", "cute"]` — A list containing three pieces of text: "Kittens", "are" and "cute" -  `["Kittens", 123, ["are", "cute"]]` — A list containing three values of different types: some text, a number and another list. Example of programmatic composition: ["Kittens", "are", "cute"] list = [] list.push "Kittens" list[1] = "are" list[list.length] = "cute" print list ### Objects The Object type is fundamental to Move (and JavaScript) as all other values are in fact Objects. E.g. a Number is a special type of Object. We say that "Move contains five different types of values" which is a simplification. Move has in fact only one type — Object — but at the same time, the language and the runtime *treats some Object subtypes differently*, like Numbers which can be used for mathematical operations or text which when "added" together creates a new piece of text being the two texts glued together. Therefore we simplify value types by saying there's only five of them. An Object is a set of (unique) keys with associated values. Keys must be text values, but an associated value can be of any type. Objects are denoted by a pair of curly brackets ("{" and "}") holding zero or more key-value pairs. Keys are written either as regular text with wrapping quotation marks or without wrapping quotation marks for text which conforms to the rule that it is a valid name (starts with a-z, A-Z, _ or $ and is followed by zero or more letters, numbers, etc). A key is terminated by a colon character and is followed by a value expression. Two successive key-value pairs are separated by a comma character. -  `{a:1, b:2}` — An object with two pairs: Key "a" represents the value 1 and key "b" represents the value 2. Example: 1 2 undefined 3 obj = {a:1, "b-B":2} print obj.a print obj["b-B"] print obj.c obj.c = 3 print obj.c ### Functions Functions are denoted by a circumflex accent character ("^") optionally followed by argument declarations wrapped in a parenthesis character pair ("(" and ")"), finally followed by a block of code wrapped in a pair of curly bracket characters ("{" and "}"). The block of code in a function has it's own scope — a variable defined (assigned for the first time) in such a block will "live" in that block, thus any references to that variable *before* the declaration of the code block will refer to *another*, probably undefined, variable. The last statement in a function's code block is *returned*. There's also a special "return" keyword which can be used to prematurely return a value from a function. Arguments can have explicit default values which are denoted by a postfix assignment operator ("=") for the argument name followed by a value. If no explicit default value is given, the "undefined" atom is used. -  `^(a, b){ a + b }` — A function which produces the sum of two numbers -  `^{ 5 + 7 }` — A function which does not expect any arguments -  `^(a=5, b=7){ a + b }` — A function with default values for its arguments -  ^(a, b){ if (a > 4) return a; a + b } — A function which use the "return" keyword to, in some cases, prematurely return a value and stop execution of that function's code. Here is an illustrating example of how scope works. The following code will yield a reference error with the message "x is not defined" since "x" is defined in the "y" function's scope and is thus not available to the outer scope: ReferenceError: x is not defined ... y = ^{ x = 5 } y{} print x Here we assign something to x in the outer scope which will tell Move that "x" should live and be available in that (outer) scope: 5 x = 0 y = ^{ x = 5 } y{} print x ### Atoms Move has a set of "atoms" which are basically pre-defined constants with itself as its value. They are called "atoms" since there is only one single, global and immutable instance (or "version" if you will) of each of these special values: -  `undefined` — Means that something is not defined. E.g. A function's argument without an explicit default value will have this atom as its value unless provided during a call to such a function. -  `null` — Means "empty" or "nothing". Handy in the case `undefined` is not suitable (i.e. you have defined a value but it's empty). -  `true` — Represents truth and is the product of a truthy logical comparison (e.g. 4 < 6 == true) -  `false` — Represents something being false or "no" and is the product of a false logical comparison (e.g. 4 > 6 == false) Example: true true true print true != false print undefined != null Yes = true print Yes == true
# About Move TODO About the project, why, etc