Share
Explore

RyanScript

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
block foo(number n): if n < 5 then return "n is less than 5" else "n is greater than 5" return 100 + foo(100)
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)
<blank>
string cor: `Greeting 1 Paul, an apostle of Christ Jesus through the will of God, and Timothy our brother, to the church of God that is in Corinth, together with all the saints who are in all Achaia. 2 Grace to you and peace from God our Father and the Lord Jesus Christ. Thanksgiving for God’s Compassion and Comfort 3 Blessed is the God and Father of our Lord Jesus Christ, the Father of mercies and God of all comfort, 4 who comforts us in all our affliction, so that we may be able to comfort those who are in all affliction with the comfort with which we ourselves are comforted by God. 5 For just as the sufferings of Christ overflow to us, thus through Christ our comfort overflows also. 6 But if we are afflicted, it is for your comfort and salvation; if we are comforted, it is for your comfort that is at work in the patient endurance of the same sufferings that we also suffer. 7 And our hope for you is firm, because we[a] know that as you are sharers in the sufferings, so also you will be sharers in the comfort. 8 For we do not want you to be ignorant, brothers, concerning our affliction that happened in the province of Asia,[b] that we were burdened to an extraordinary degree, beyond our strength, so that we were in despair even of living. 9 But we ourselves had the sentence of death in ourselves, so that we would not be putting confidence in ourselves, but in God who raises the dead, 10 who delivered us from so great a risk of death, and will deliver us, in whom we have put our hope that he will also deliver us again, 11 while[c] you also join in helping on our behalf[d] by prayer, so that thanks may be given on our behalf[e] by many persons for this gracious gift given to us through the help of many. Paul’s Clear Conscience 12 For our reason for boasting is this: the testimony of our conscience that we conducted ourselves in the world, and especially toward you, in holiness[f] and purity of motive from God, not[g] in merely human wisdom, but by the grace of God. 13 For we are not writing anything else to you except what you can read or also understand. But I hope that you will understand completely[h], 14 just as you have also understood us in part, that we are your reason for boasting, just as you are also ours in the day of our Lord Jesus. Paul Delays His Visit to Corinth 15 And with this confidence, I was wanting to come to you previously, in order that you may have a second proof of my goodwill, 16 and through you to go to Macedonia, and to come to you again from Macedonia, and to be sent on my way by you to Judea. 17 Therefore, when I[i] was wanting to do this, perhaps then was I making use of vacillation? Or was I deciding what I was deciding according to the flesh, in order that with me my “yes” may be “yes” and my “no” may be “no” at the same time?[j] 18 But God is faithful, so that our word to you is not “yes” and “no.” 19 For the Son of God, Jesus Christ, the one who was proclaimed among you by us, by me and Silvanus and Timothy, did not become “yes” and “no,” but has become “yes” in him. 20 For as many as are the promises of God, in him they are “yes”; therefore also through him is the “amen” to the glory of God through us. 21 Now the one who establishes us together with you in Christ and who anoints us is God, 22 who also sealed us and gave the down payment of the Spirit in our hearts. 23 But I call upon God as witness against my life, that in order to[k] spare you, I did not come again to Corinth. 24 Not that we lord it over your faith, but we are fellow workers for your joy, because by faith you stand firm.` string word: "submit" var corList: cor.split(" ") return cor
Empty Script
Script
block foo(number n): if n < 5 then return "n is less than 5" else "n is greater than 5"
return 100 + foo(100)
Run Script
Run Script
Auto Run on Edit
Output
Verbosity
Log
Log Objects
group
debug
debug
debug
debug
debug
debug
debug
debug
debug
debug
debug
debug
log
warn
warn
warn
warn
warn
warn
log
group
group
group
log
debug
debug
log
log
group
log
debug
debug
debug
group
debug
group
log
debug
debug
log
debug
group
group
debug
info
info
warn
group
group
log
debug
debug
log
debug
group
group
debug
info
info
info
info
New Script
Show hidden columns
Log Levels
0
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.