Functions that mostly work with collections (blocks / lists).
Builtin(2): Takes two integers and returns a block of integers between them. (Will change to lazy list/generator later)
range 1 5
; returns { 1 2 3 4 5 }
Builtin(1): Accepts a Block, List or String and returns the first item.
first { 1 2 3 4 5 }
; returns 1
first list { 1 2 3 4 5 }
; returns 1
first "12345"
; returns "1"
try { first { } } |type?
; returns error
try { first list { } } |type?
; returns error
try { first "" } |type?
; returns error
Builtin(1): Accepts a Block, List or String and returns all but first item.
rest { 1 2 3 4 5 }
; returns { 2 3 4 5 }
rest list { 1 2 3 4 5 }
; returns L[ 2 3 4 5 ]
rest "12345"
; returns "2345"
try { rest { } } |type?
; returns error
try { rest list { } } |type?
; returns error
try { rest "" } |type?
; returns error
Builtin(2): Accepts a Block, List or String and an Integer N, returns all but first N items.
rest\from { 1 2 3 4 5 } 2
; returns { 3 4 5 }
rest\from list { 1 2 3 4 5 } 2
; returns L[ 3 4 5 ]
rest\from "12345" 2
; returns "345"
try { rest\from { } } |type?
; returns error
try { rest\from list { } } |type?
; returns error
try { rest\from "" } |type?
; returns error
Builtin(1): Accepts a Block, List or String and returns the second value in it.
second { 1 2 3 4 5 }
; returns 2
second list { 1 2 3 4 5 }
; returns 2
second "12345"
; returns "2"
try { second { } } |type?
; returns error
try { second list { } } |type?
; returns error
try { second "" } |type?
; returns error
Builtin(1): Accepts a Block, List or String and returns the third value in it.
third { 1 2 3 4 5 }
; returns 3
third list { 1 2 3 4 5 }
; returns 3
third "12345"
; returns "3"
try { third { } } |type?
; returns error
try { third list { } } |type?
; returns error
try { third "" } |type?
; returns error
Builtin(2): Accepts a Block, List or String and Integer N, returns the N-th value.
nth { 1 2 3 4 5 } 4
; returns 4
nth list { 1 2 3 4 5 } 4
; returns 4
nth "12345" 4
; returns "4"
try { nth { } } |type?
; returns error
try { nth list { } } |type?
; returns error
try { nth "" } |type?
; returns error
Builtin(2):
{ 11 22 33 } |_-> 1
; returns 22
list { 11 22 33 } |_-> 1
; returns 22
dict { "a" 11 "b" 22 "c" 33 } |_-> "b"
; returns 22
Builtin(2):
2 <- { 11 22 33 }
; returns 33
2 <- list { 11 22 33 }
; returns 33
"c" <- dict { "a" 11 "b" 22 "c" 33 }
; returns 33
Builtin(1): Accepts a Block, List or String and returns the last value in it.
last { 1 2 3 4 5 }
; returns 5
last list { 1 2 3 4 5 }
; returns 5
last "12345"
; returns "5"
try { last { } } |type?
; returns error
try { last list { } } |type?
; returns error
try { last "" } |type?
; returns error
Builtin(2): Accepts a Block, List or String and an Integer N, returns the first N values.
head { 1 2 3 4 5 } 2
; returns { 1 2 }
head { 1 2 3 4 5 } 10
; returns { 1 2 3 4 5 }
head { } 2
; returns { }
head list { 1 2 3 4 5 } 2
; returns L[ 1 2 ]
head list { 1 2 3 4 5 } 10
; returns L[ 1 2 3 4 5 ]
head list { } 2
; returns L[]
head "12345" 2
; returns "12"
head "12345" 10
; returns "12345"
head "" 2
; returns ""
Builtin(2): Accepts a Block, List or String and Integer N, returns the last N items.
tail { 1 2 3 4 5 } 2
; returns { 4 5 }
tail { 1 2 3 4 5 } 10
; returns { 1 2 3 4 5 }
tail { } 2
; returns { }
tail list { 1 2 3 4 5 } 2
; returns L[ 4 5 ]
tail list { 1 2 3 4 5 } 10
; returns L[ 1 2 3 4 5 ]
tail list { } 2
; returns L[]
tail "12345" 2
; returns "45"
tail "12345" 10
; returns "12345"
tail "" 2
; returns ""
Builtin(1): Accepts a collection (String, Block, Dict, Spreadsheet) and returns it's length.
length? "1234567"
; returns 7
{ 1 2 3 4 5 } .length?
; returns 5
list { 1 2 3 } |length?
; returns 3
Builtin(1): Constructs a List from the Block of values.
list { "a" 1 "b" 2 } |type?
; returns list
Builtin(1): Constructs a Dict from the Block of key and value pairs.
dict { "a" 1 "b" 2 } |type?
; returns dict
Builtin(1): Constructs a Dict from the Block of key and value pairs.
min { 8 2 10 6 }
; returns 2
min list { 8 2 10 6 }
; returns 2
try { min { } } |type?
; returns error
try { min list { } } |type?
; returns error
Builtin(1): Constructs a Dict from the Block of key and value pairs.
max { 8 2 10 6 }
; returns 10
max list { 8 2 10 6 }
; returns 10
try { max { } } |type?
; returns error
try { max list { } } |type?
; returns error
Builtin(1): Constructs a Dict from the Block of key and value pairs.
avg { 8 2 10 6 }
; returns 6.500000
avg list { 8 2 10 6 }
; returns 6.500000
try { avg { } } |type?
; returns error
try { avg list { } } |type?
; returns error
Builtin(1): Accepts a Block or List of values and returns the sum.
sum { 8 2 10 6 }
; returns 26
sum { 8 2 10 6.500000 }
; returns 26.500000
sum { }
; returns 0
sum list { 8 2 10 6 }
; returns 26
sum list { 8 2 10 6.500000 }
; returns 26.500000
sum list { }
; returns 0
Builtin(2): Accepts a block or list of values and returns only unique values.
union { 8 2 } { 1 9 } |length?
; returns 4
union { } { 1 9 } |length?
; returns 2
union { } { }
; returns { }
Pure Builtin(2): Finds the intersection of two values.
intersection { 1 3 5 6 } { 2 3 4 5 }
; returns { 3 5 }
intersection { } { 2 3 4 }
; returns { }
intersection { } { }
; returns { }
Builtin(2): Accepts Rye value and Tagword with a Block or String. Appends Rye value to Block/String in place, also returns it .
{ 3 2 3 5 3 2 } .list .unique .length?
; returns 3
Functions for usual HOF patterns, map, reduce, filter.
Pure Builtin(2): Maps values of a block to a new block by evaluating a block of code.
map { 1 2 3 } { + 1 }
; returns { 2 3 4 }
map { } { + 1 }
; returns { }
map { "aaa" "bb" "c" } { .length? }
; returns { 3 2 1 }
map list { "aaa" "bb" "c" } { .length? }
; returns L[ 3 2 1 ]
map list { 3 4 5 6 } { .factor-of 3 }
; returns L[ 1 0 0 1 ]
map list { } { + 1 }
; returns L[]
map "123" { .to-integer }
; returns { [NIL][NIL][NIL]1 2 3 }
map "123" to-integer
; returns { 1 2 3 }
map "" { + "-" }
; returns { }
Pure Builtin(3): Maps values of a block to a new block by evaluating a block of code.
map\pos { 1 2 3 } 'i { + i }
; returns { 2 4 6 }
map\pos { } 'i { + i }
; returns { }
map\pos list { 1 2 3 } 'i { + i }
; returns L[ 2 4 6 ]
map\pos list { } 'i { + i }
; returns L[]
map\pos "abc" 'i { + i }
; returns { [NIL][NIL][NIL]"a1" "b2" "c3" }
map\pos "" 'i { + i }
; returns { }
Pure Builtin(2): Filters values from a seris based on return of a injected code block.
filter { 1 2 3 4 } { .even }
; returns { 2 4 }
filter { 1 2 3 4 } even
; returns { 2 4 }
filter { } { .even }
; returns { }
filter list { 1 2 3 4 } { .even }
; returns L[ 2 4 ]
filter list { 1 2 3 4 } even
; returns L[ 2 4 ]
filter list { } { .even }
; returns L[]
filter "1234" { .to-integer .even }
; returns { "2" "4" }
filter "01234" to-integer
; returns { "1" "2" "3" "4" }
filter "" { .to-integer .even }
; returns { }
Pure Builtin(2): Seek over a series until a Block of code returns True and return the value.
seek { 1 2 3 4 } { .even }
; returns 2
seek list { 1 2 3 4 } { .even }
; returns 2
seek "1234" { .to-integer .even }
; returns "2"
try { seek { 1 2 3 4 } { > 5 } } |type?
; returns error
try { seek list { 1 2 3 4 } { > 5 } } |type?
; returns error
try { seek "1234" { .to-integer > 5 } } |type?
; returns error
Builtin(2): Purges values from a series based on return of a injected code block.
purge { 1 3 3 } { .even }
; returns { 1 3 }
purge { } { .even }
; returns { }
purge list { 1 2 3 } { .even }
; returns L[ 1 3 ]
purge list { } { .even }
; returns L[]
purge "1234" { .to-integer .even }
; returns { "1" "3" }
purge "" { .to-integer .even }
; returns { }
Pure Builtin(3): Reduces values of a block to a new block by evaluating a block of code ...
reduce { 1 2 3 } 'acc { + acc }
; returns 6
reduce list { 1 2 3 } 'acc { + acc }
; returns 6
reduce "abc" 'acc { + acc }
; returns "cba"
try { reduce { } 'acc { + acc } } |type?
; returns error
try { reduce list { } 'acc { + acc } } |type?
; returns error
try { reduce "" 'acc { + acc } } |type?
; returns error
Pure Builtin(4): Reduces values of a block to a new block by evaluating a block of code ...
fold { 1 2 3 } 'acc 1 { + acc }
; returns 7
fold { } 'acc 1 { + acc }
; returns 1
fold list { 1 2 3 } 'acc 1 { + acc }
; returns 7
fold list { } 'acc 1 { + acc }
; returns 1
fold "abc" 'acc "123" { + acc }
; returns "cba123"
fold "" 'acc "123" { + acc }
; returns "123"
Pure Builtin(2): Partitions a series by evaluating a block of code.
partition { 1 2 3 4 } { > 2 }
; returns { { 1 2 } { 3 4 } }
partition { "a" "b" 1 "c" "d" } { .is-integer }
; returns { { "a" "b" } { 1 } { "c" "d" } }
partition { "a" "b" 1 "c" "d" } is-integer
; returns { { "a" "b" } { 1 } { "c" "d" } }
partition { } { > 2 }
; returns { { } }
partition list { 1 2 3 4 } { > 2 }
; returns L[ L[ 1 2 ] L[ 3 4 ] ]
partition list { "a" "b" 1 "c" "d" } is-integer
; returns L[ L[ a b ] L[ 1 ] L[ c d ] ]
partition list { } { > 2 }
; returns L[ L[] ]
partition "aaabbccc" { , }
; returns L[ aaa bb ccc ]
partition "" { , }
; returns L[ ]
partition "aaabbccc" is-string
; returns L[ aaabbccc ]
Function(4)
{ } .list .group { .first }
; returns [
; ]
try { { 1 2 3 4 } .group { .even } } |type?
; returns error
Builtin(3): Accepts a number, initial value and a block of code. Does the block of code number times, injecting the number.
produce 5 0 { + 3 }
; returns 15
Pure Builtin(2): Reduces values of a block or list by evaluating a block of code and summing the values.
sum-up { 1 2 3 } { * 10 }
; returns 60
sum-up { 1 2 3 } { * 2.500000 }
; returns 15.000000
sum-up { 1 2.500000 3.500000 } { * 10 }
; returns 70.000000
sum-up { "1" "2" "3" } to-integer
; returns 6
sum-up { } { * 10 }
; returns 0
sum-up list { 1 2 3 } { * 10 }
; returns 60
sum-up list { 1 2.500000 3.500000 } { * 10 }
; returns 70.000000
sum-up list { "1" "2" "3" } to-integer
; returns 6
sum-up list { } { * 10 }
; returns 0
Functions for handling and working with Context.
Builtin(0): Returns current context.
current-ctx |type?
; returns ctx
Builtin(0): Returns parent context of the current context.
cc: context { f: does { parent-ctx |type? } } , cc
; returns ctx
Builtin(1): Creates a new context with no parent
context { x: does { 1 + 1 } } :cc , cc
; returns 2
Builtin(1):
isolate { x: does { 1 + 1 } } :cc , try { cc } |type?
; returns error
Builtin(1):
cc: raw-context { name: "Jim" } |type?
; returns ctx
Builtin(1): Creates a new context with current parent, returns last value
private { x: 3 , x + 30 } :x
; returns 33
Builtin(2): Extends a context with a new context in place and returns it.
c1: context { x: 1 } , c2: extend c1 { y: 2 } , c2
; returns 1
Builtin(2):
isolate { x: does { 1 + 1 } } |bind current-ctx :cc , cc
; returns 2
Builtin(1): Accepts a Context and unbinds it from it's parent Context.
context { x: does { 1 + 1 } } |unbind :cc , try { cc } |type?
; returns error
Functions that print values to stdio
Builtin(1): Turn value to it's string representation.
mold 33
; returns "33"
Builtin(1): Turn value to it's string representation.
mold\nowrap "33"
; returns ""33""
Builtin(1): Takes a block of code and does (runs) it.
capture-stdout { "out" .print , "not this" }
; returns "out
; "
Pure Builtin(1): Retunrs (dumps) content of a function.
fn { x } { x + 1 } |dump
; returns { fn { x } { x ._+ 1 } }
Pure Builtin(1): Get docstring of the passed context.
fn { x "docstring" } { x + 1 } |doc\of?
; returns "docstring"
Builtin(1): Loads a string into Rye values.
load "1 2 3" |type?
; returns block
load "1 2 3" |length?
; returns 3
load "1 2 { print 4 }" |third |length?
; returns 2
load "1 2 { print 4 }" |third |first |type?
; returns word
Functions for handling and working with Context.
Builtin(2): Create a spreadsheet by accepting block of column names and flat block of values
spreadsheet { "name" "rating" "weight" } { "Enno" 4.300000 120 "Enya" 6 132 "Shizuuchi" 7.200000 168 "Kunishima" 2 68 } :spr |type?
; returns spreadsheet
spr |length?
; returns 4
spr |columns? |length?
; returns 3
spr .first |_-> "name"
; returns "Enno"
[name rating weight]
name
spr .where-equal 'name "Enya" |length?
; returns 1
spr .where-lesser 'weight 130 |length?
; returns 2
Builtin(1): Create a spreadsheet by accepting block of dicts
spreadsheet { "a" "b" } { "aa" "2" "bb" "4" } |autotype 1.000000
; returns a |b |
; {aa} |{2} |
; {bb} |{4} |
;
spreadsheet { "a" "b" } { "aa" "2.1" "bb" "4.3" } |autotype 1.000000
; returns a |b |
; {aa} |{2.1} |
; {bb} |{4.3} |
;
Builtin(1): Create a spreadsheet by accepting block of dicts
to-spreadsheet vals { dict { "a" 1 b 2 } dict { "a" 4 "b" 5 } }
; returns b |a |
; {2} |{1} |
; {5} |{4} |
;
to-spreadsheet vals { dict { "a" 1 b 2 "c" 3 } dict { "a" 4 "b" 5 } }
; returns a |b |c |
; {1} |{2} |{3} |
; {4} |{5} |{} |
;