Share
Explore

RyanScript

RM
Ryan Martens
Basics
value types are: boolean, number, string, block, and ref
but don’t use the ref value type... use the alias keyword instead because it’s less confusing to use
booleans, numbers and strings are generally what you expect from javascript... except NaN causes (usually fatal) issues.
block values wear several hats:
blocks have code (expressions) that can be called later (ie, functions)
parameters can be defined at the time of declaration (or after, but that’s weird)
blocks have properties, which are simply variables scoped to that namespace.
each block instance can only be called once, but you don’t usually need to worry about that because calling a block in a loop or with the f(x) syntax will automatically clone it for you before calling. But if you declare a block literal, it will be called right away and then you can’t call it as a function afterward (without errors or unexpected results)
Syntax
Hopefully the syntax is mostly guessable, but there are a few things to note.
no semicolons ; allowed... it will error (but almost all the other symbols on the keyboard are used for something)
variable assignment is done with the : operator (not =), and likewise +:, -:, etc
if statements currently require a then keyword (even for blocks) to separate the condition from the action (else is optional).
Command words must be the first word in the expression (return, if, break, for, etc). If you want to use these in conjunction with operators, best to use (parentheses)
same thing goes for variable declarations (but not assignments)
the . operator is a crafty creature and has 4 (more like 3.5) uses:
property access (eg, foo.prop)
function call (eg, “hello world”.slice(5))
send a command up one or more levels
eg, within an if block or loop, ..return something will return the value of something to the parent of the parent of the current block
likewise, in a nested loop block, .break will stop the outer loop (normal break to stop the inner loop)
declare a variable in the parent block (not yet implemented, probably not useful)
In many cases, you can omit the () when calling a function with no parameters
this happens when you use a block in a context where a non-block value is expected
example: ”hello”.length is equivalent to ”hello”.length() in most contexts
the return statement is required for the root level; otherwise it just gives an error
Why? because the root level is a block and blocks without a return statement return themselves, and coda doesn’t know how to display that in it’s little output chip.
quick tip: blocks act like functions when declared like block foo(): ... but like objects when declared without the ().
Features
Operators: ., [, (, =>, ++, --, ?, -, +, $, @, #, !, *, /, %, +, -, <, >, <=, >=, ~, ~~, =, ==, &, &&, ||, ??, :
prefix operators !, +, $, @ convert the value to boolean, number, string, or reference respectively (while the ! also negates)
postfix ? is used to check if a variable exists or not. Tells you nothing about it’s value
Commands/Keywords: return, break, continue, if..then..else, for..in, debugger,
Built-in functions: type, length, range, trim, slice, push, pop, filter, map, sqrt,
type(value) returns a string indicating the type of the value passed
range operates pretty much like python’s range function
Variable declaration words: global, prop, local, temp, var, const, boolean, number, string, block, alias, ref
Caveats & Issues
occasionally there may be operators that execute out of order (most notably a property access after function call, eg, foo().prop) For now, just fix it with (parentheses)
some errors and warning are reported, but sometimes you’ll simply get a wrong result without an error message

Scripts
0
Search
Empty Script
return "Can you have ian infinitely long lateral string, or will it get cut off somehow................................................................................................."
Hello World
return "Hello world"
Greeting to
/* Variables are generally declared with a type such as boolean, number, string. If the type is omitted, the variable will accept any value without converting. */ string greeting: "Hello" string to: "world" return greeting & " " & to & to & "to" // the string concatenation operator is &, but the + operator (generally reserved for math) also works in a pinch
const hoisting
/* any variables declared with the const keyword will be ‘hoisted’, ie, declared and available for use immediately upon block initialization. However, if the value of the const depends on a non-const value ... it may or may not bork*/ number six: plusOne(6) - 1 return six+1 const plusOne(number param1: 0+0): param1++ local number result if param1 then result: param1 else result: -1 return result
New Person
const block newPerson(string name, number age): if name == "" then name: "no name" if age < 0 then age: 0 - age var string foo var block Ryan: prop string name: "Ryan" prop number age: 30 foo: "hello world" var out: foo if !out? then return "🙁" else return 'output is:\n' & out // return if !foo.bar? then "no foobar" else if foo.bar? then "foo.bar"
Array Block
block sumNums: number one: 1 number two: 1 number ["five"]: 5 // this is the same as five (without square brackets and quotes) var [3]: 100 number [4]: (0-1)*1/2 // skipping 5 and 6 number [7]: 0 string number result: 1 for number i in range(0,8) if !(sumNums[i] == null) then result +: sumNums[i] return result
<blank>
block newPerson(string name, number age): "lines of code" var Ryan: newPerson("Ryan", 30) var Veron: newPerson(age:30, name:"Veron") return Veron.name
<blank>
block newPerson(string name, number age): if name = "" || !name then name: "no name" block greet(): return "Hello " + name var ryan: newPerson("Ryan", 30) return $ryan.greet
Array Literal
var myList: [1,2,3] number sum: 0 for i in myList sum +: i return sum
another loop
number num: 10 for n in range(1,10) num +: n return num
the mapper
block sumNums: number one: 1 number two: 2 number three: 5 var four: 10 number five: -1/2 number sum: 0 string result: "First call: " for number i in range(0, sumNums.length) sum +: sumNums[i] result &: sum & "\nSecond call: " block timesTen(number x): return x*10 sumNums.map(timesTen) sum: i: 0 for i in range(0,sumNums.length) sum +: sumNums[i] return result & sum
<blank>
block plusOne(number x): return x + 1 return "Hello " & plusOne(9)
Empty Script
Script
return "Can you have ian infinitely long lateral string, or will it get cut off somehow................................................................................................."
Run Script
Run Script
Auto Run on Edit
Output
Can you have ian infinitely long lateral string, or will it get cut off somehow.................................................................................................
Verbosity
Log
Log Objects
group
debug
debug
log
warn
warn
warn
warn
warn
warn
log
group
group
group
debug
info
info
New Script
Show hidden columns
Log Levels
0
Search
Symbol
Name
Number
Display
Column
1
Error
1
❗ Error
2
2
⚠️
Warning
2
⚠️ Warning
2
3
🛈
Info
3
🛈 Info
2
4
>
Log
4
> Log
2
5
🐛
Debug
5
🐛 Debug
2
6
👉
Trace
6
👉 Trace
2
There are no rows in this table



Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.