Rye reference: Basics

Printing functions

Functions that print values to stdout.

print

Builtin(1): Prints a value and adds a newline.

print 123
; prints "123
; "

prn

Builtin(1): Prints a value without newline.

prn 123
; prints "123"

prns

Builtin(1): Prints a value and adds a space.

prns 123
; prints "123 "

print\val

Builtin(2): Prints a value and adds a newline.

print\val 33 "value is: {{}}"
; prints "value is: 33
; "

probe

Builtin(1): Prints a probe of a value.

probe 33
; prints "[Integer: 33]
; "

Logic functions

Function that help with logical operations.

true

Pure Builtin(0): Returns a truthy value.

true
; returns 1

false

Pure Builtin(0): Returns a falsy value.

false
; returns 0

not

Pure Builtin(1): Turns a truthy value to a non-truthy and reverse.

not 0
; returns 1
not 1
; returns 0

and

Pure Builtin(2): Bitwise AND operation between two values.

1 .and 0
; returns 0
1 .and 1
; returns 1
0 .and 0
; returns 0

or

Pure Builtin(2): Bitwise OR operation between two values.

1 .or 0
; returns 1
1 .or 1
; returns 1
0 .or 0
; returns 0

xor

Pure Builtin(2): Bitwise XOR operation between two values.

0 .xor 0
; returns 0
1 .xor 1
; returns 0
0 .xor 1
; returns 1
1 .xor 0
; returns 1

all

Builtin(1): Takes a block, if all values or expressions are truthy it returns the last one, otherwise false.

all { 1 1 1 }
; returns 1
{ 0 0 1 } .all
; returns 0

any

Builtin(1): Takes a block, if any of the values or expressions are truthy, the it returns that one, in none false.

any { 0 0 1 }
; returns 1
{ 0 0 0 } .any
; returns 0

Working with numbers

Functions that mostly work with numbers.

inc

Pure Builtin(1): Returns integer value incremented by 1.

inc 100
; returns 101

is-positive

Pure Builtin(1): Returns true if integer is positive.

is-positive 1
; returns 1
0 .is-positive
; returns 0

is-zero

Pure Builtin(1): Returns true if integer is zero.

is-zero 0
; returns 1
0 .is-zero
; returns 1
is-zero 0.000000
; returns 1
is-zero 0.100000
; returns 0

factor-of

Pure Builtin(2): Checks if a first argument is a factor of second.

factor-of 10 2
; returns 1
10 .factor-of 3
; returns 0

odd

Pure Builtin(1): Checks if a number is odd.

odd 3
; returns 1

even

Pure Builtin(1): Checks if a number is even.

even 2
; returns 1

mod

Pure Builtin(2): Calculates module (remainder) of two integers.

3 .mod 2
; returns 1

Working with strings

Functions that mostly work with strings.

capitalize

Pure Builtin(1): Takes a String and returns the same String, but with first character turned to upper case.

capitalize "anne"
; returns "Anne"

to-lower

Pure Builtin(1): Takes a String and returns the same String, but with all characters turned to lower case.

to-lower "ANNE"
; returns "anne"

to-upper

Pure Builtin(1): Takes a String and returns the same String, but with all characters turned to upper case.

to-upper "anne"
; returns "ANNE"

join

Pure Builtin(1): Joins Block or list of values together.

join { "Marry" "Anne" }
; returns "MarryAnne"

join\with

Pure Builtin(2): Joins Block or list of values together.

join\with { "Marry" "Anne" } ","
; returns "Marry,Anne"

split

Pure Builtin(2): Splits a string into a block of values using a separator

split "Marry,Anne" ","
; returns { "Marry" "Anne" }

split\quoted

Pure Builtin(3): Splits a line of string into values by separator by respecting quotes

split\quoted ""Marry,Anne",Joe" "," """
; returns { "Marry,Anne" "Joe" }

split\every

Pure Builtin(2): Splits a string into a block of values using a separator

split\every "abcbce" 3
; returns { "abc" "bce" }

Many of functions that work with other collections also work with strings.

Conditional functions

Program flow control functions

if

Pure Builtin(2): Basic conditional. Takes a condition and a block of code.

if 1 { 101 }
; returns 101
if 0 { 101 }
; returns 0

otherwise

Pure Builtin(2): Conditional if not. Takes condition and a block of code.

otherwise 1 { 101 }
; returns 0
otherwise 0 { 101 }
; returns 101

^if

Pure Builtin(2): Basic conditional with a Returning mechanism when true. Takes a condition and a block of code.

^if 0 { 101 }
; returns 0

^otherwise

Pure Builtin(2): Basic conditional with a Returning mechanism when true. Takes a condition and a block of code.

^otherwise 1 { 101 }
; returns 0

either

Pure Builtin(3): The if/else conditional. Takes a value and true and false block of code.

either 1 { 101 } { 202 }
; returns 101
either 0 { 101 } { 202 }
; returns 202

switch

Builtin(2): Classic switch function. Takes a word and multiple possible values and block of code to do.

switch 1 { 1 { 101 } 2 { 202 } }
; returns 101
switch 2 { 1 { 101 } 2 { 202 } }
; returns 202

cases

Builtin(2): Similar to Case function, but checks all the cases, even after a match. It combines the outputs.

cases 1 { { 1 } { + 10 } { 1 } { + 100 } }
; returns 111
cases 1 { { 0 } { + 10 } { 1 } { + 100 } }
; returns 101

Looping functions

Program flow control functions

loop

Pure Builtin(2): Basic conditional. Takes a condition and a block of code.

loop 3 { prns "x" }
; prints "x x x "

for

Pure Builtin(2): Conditional if not. Takes condition and a block of code.

for { 1 2 3 } { prns "x" }
; prints "x x x "
{ "a" "b" "c" } .for { .prns }
; prints "a b c "

forever

Builtin(1): Accepts a block and does it forever.

forever { "once" .prn .return }
; prints "once"

forever\with

Builtin(2):

forever\with 1 { .prn .return }
; prints "1"

Doers and evaluators

Functions that do code and evaluate blocks.

do

Builtin(1): Takes a block of code and does (runs) it.

do { 101 + 101 }
; returns 202

do-in

Builtin(2): Takes a Context and a Block. It Does a block inside a given Context.

cc: context { x: 101 } do-in cc { x + 101 }
; returns 202

with

Builtin(2): Takes a value and a block of code. It does the code with the value injected.

1 .with { + 100 }
; returns 101

try

Builtin(1): Takes a block of code and does (runs) it.

try { 10 + unknown } |type?
; returns error

do-in\try

Builtin(2): Takes a Context and a Block. It Does a block inside a given Context.

ctx: context { x: 101 } do-in\try ctx { x / 0 } |type?
; returns error

vals

Builtin(1): Takes a block of Rye values and evaluates each value or expression.

x: 101 vals { x }
; returns { 101 }
name: "Anne" vals { name "Goodall" }
; returns { "Anne" "Goodall" }
y: 202 vals { 101 y y + 101 }
; returns { 101 202 303 }

vals\with

Builtin(2): Evaluate a block with injecting the first argument.

vals\with 100 { + 1 }
; returns { 101 }

time-it

Builtin(1): Accepts a block, does it and times it's execution time.

time-it { 1 + 1 }
; returns 0

Function creating functions

Functions that create functions.

does

Pure Builtin(1): Creates a function without arguments.

f: does { prns "Hey" } f f
; prints "Hey Hey "

fn

Pure Builtin(2): Creates a function.

f: fn { x } { prns x } f "A" f "B"
; prints "A B "

fn1

Pure Builtin(1): Creates a function that accepts one anonymouse argument.

f: fn1 { .prns } f "A" f "B"
; prints "A B "

pfn

Pure Builtin(2): Creates a pure function.

add10: pfn { x } { x + 10 } add10 9
; returns 19
x: 10 f: pfn { } { prns 1 } try { f } |type?
; returns error
x: 10 f: pfn { } { x } try { f } |type?
; returns error

Pure functions only have access to other pure functions.

closure

Pure Builtin(2): Creates a function with specific context.

x: 10 cl: fn { } { prns x } , context { x: 99 cl }
; prints "99 "
x: 10 cl: closure { } { prns x } , context { x: 99 cl }
; prints "10 "