EasyCoder documentation
Values
A value in EasyCoder can be numeric, boolean or string. Numeric values are just integers and we provide 4-function arithmetic to manipulate them - see the add, take, multiply and divide commands. Boolean values can be true or false, though in practice you rarely need to use either of these words. Note that false is not the same as 0 and true is not the same as 1 - booleans and numbers are not interchangeable the way they are in JavaScript.
String values are just lengths of text enclosed in curly braces. Any other characters can be used inside the braces; if you want include the braces themselves you can represent them by { and }. A break (newline) is represented by br.
Strings can be built from a series of component parts joined by the word cat (short for catenate).
Examples (see Commands):
put 5 into N
add 31 to N
multiply N by 15 giving Result
divide Result by N
set Flag
clear Flag
toggle Flag
put `The quick brown fox` into MyText
put `My name is "Earl"` into Name
put `http://mysite.com/page` cat N into URL
put `Line 1` cat br cat `Line 2` into Lines
Special values
Core domain
The core domain handles the following values:
true
returns the boolean value true.
false
returns the boolean value false.
empty
returns an empty string.
newline
returns a new line character.
now
returns the timestamp - the number of seconds since the epoch (January 1, 1970).
the index of
returns the (numeric) value of the index of a named variable. Example:
put the index of Items into Count
modulo
returns one value modulo another. Example:
put Count modulo 10 into Count
property {name} of {variable containing JSON data}
returns the value of the named property. Example:
put property `title` of JSONText into Title
random
returns a random number between 0 and the value given. Examples:
add random 10 to Count
take random Size from Value giving V
cos {angle} radius {radius}
returns the cosine of the angle given multiplied by the specified radius. Example:
put cos X radius R into Angle
sin {angle} radius {radius}
returns the sine of the angle given multiplied by the specified radius. Example:
put sin X radius R into Angle
tan {angle} radius {radius}
returns the tangent of the angle given multiplied by the specified radius. Example:
put tan X radius R into Angle
left {count} of {Text}
returns the leftmost {count} characters of {Text}. Example:
put left 5 of Text into Prefix
right {count} of {Text}
returns the rightmost {count} characters of {Text}. Example:
put right 5 of Text into Suffix
the position of [the last] {needle} in {haystack}
returns the position in {haystack} of either the first or the last occurrence of {needle}, where both {needle} and {haystack} are text values. Examples:
put the position of `fox` in `The quick brown fox jumps over the lazy dog` into Pos (Pos=16)
put the position of the last `dot` in `dot dot dot` into P (P=8)
encode {variable}
encodes the variable using the current encoding (see set). Example:
encode Content
decode {variable}
decodes the variable using the current encoding (see set). Example:
decode Content
lowercase {value}
Converts the value to lower case; useful for string comparisons. Example:
lowercase Text
element {value} of {variable}
Gets the requested element of {variable}, assuming it to be a JSON string. Examples:
element 5 of MyJSON
element N of Value
property {value} of {variable}
Gets the requested property of {variable}, assuming it to be a JSON string. Example:
property `id` of Record
the index of {variable}
Gets the current index of {variable}. All variables in EasyCoder are arrays, though most only have a single element. Where they have more than one (as set by set the index of {variable} to {value}) the index always points to the current element and the variable acts as if only has that one element. Example:
put the index of Values into M
the value of {value}
Gets the numeric value of {value}. Examples:
put the value of `459` into N459
put the value of ThisString into Code
Browser domain
The browser domain has values for the width and height of a DOM element:
(the) width of {variable}
(the) height of {variable}
returns the width or height of the named element.
Examples:
put the width of Container into Width
put the height of Button into H
JSON domain
The json domain has a single special value:
the json size of {variable containing a JSON array}
returns the size of the given JSON array.
Example:
put the json size of Gallery into NPaintings