- testing-status
- is-zero
- is-one
- evens
- odds
- inc
- dec
- pos/neg
- is-functions
- prepend
- append
- concat2
- pluck
- get
- first
- ffirst
- second
- rest
- end
- butlast
- is-empty
- swap
- nth
- check-pipe
- flatten
96 tests passed out of 96
100% of tests are passing
These functions largely assume numbers, lists, and strings. The list operations are of dubious usefulness for users, however.
works with text, nums, and inexact-nums
is-zero 0
is-zero (num 0)
is-zero (inexact-num 0)
▶ $true
is-zero 1
is-zero (randint 1 100)
is-zero (inexact-num (randint 1 100))
▶ $false
works with text, nums, and inexact-nums
is-one 1
is-one (num 1)
is-one (inexact-num 1)
▶ $true
is-one 0
is-one (num 0)
is-one (inexact-num 0)
▶ $false
only works with strings & nums
range -5 6 | each $is-even~
range -5 6 | each $to-string~ | each $is-even~
▶ $false
▶ $true
▶ $false
▶ $true
▶ $false
▶ $true
▶ $false
▶ $true
▶ $false
▶ $true
▶ $false
fails with inexact-nums
is-even 5.0
▶ [&reason=<unknown wrong type for arg #0: cannot parse as integer: 5.0> &stack-trace=<...>]
only works with strings & nums
range -5 6 | each $is-odd~
range -5 6 | each $to-string~ | each $is-odd~
▶ $true
▶ $false
▶ $true
▶ $false
▶ $true
▶ $false
▶ $true
▶ $false
▶ $true
▶ $false
▶ $true
fails with inexact-nums
is-odd 5.0
▶ [&reason=<unknown wrong type for arg #0: cannot parse as integer: 5.0> &stack-trace=<...>]
works with text, nums, and inexact-nums
range -5 6 | each $inc~
range -5 6 | each $to-string~ | each $inc~
▶ -4
▶ -3
▶ -2
▶ -1
▶ 0
▶ 1
▶ 2
▶ 3
▶ 4
▶ 5
▶ 6
range -5 6 | each $inexact-num~ | each $inc~
▶ -4.0
▶ -3.0
▶ -2.0
▶ -1.0
▶ 0.0
▶ 1.0
▶ 2.0
▶ 3.0
▶ 4.0
▶ 5.0
▶ 6.0
works with text, nums, and inexact-nums
range -5 6 | each $dec~
range -5 6 | each $to-string~ | each $dec~
▶ -6
▶ -5
▶ -4
▶ -3
▶ -2
▶ -1
▶ 0
▶ 1
▶ 2
▶ 3
▶ 4
range -5 6 | each $inexact-num~ | each $dec~
▶ -6.0
▶ -5.0
▶ -4.0
▶ -3.0
▶ -2.0
▶ -1.0
▶ 0.0
▶ 1.0
▶ 2.0
▶ 3.0
▶ 4.0
works with text, nums, and inexact-nums
each $pos~ [-1 1]
each $neg~ [1 -1]
each $pos~ [(num -1) (num 1)]
each $neg~ [(num 1) (num -1)]
each $pos~ [(inexact-num -1) (inexact-num 1)]
each $neg~ [(inexact-num 1) (inexact-num -1)]
▶ $false
▶ $true
predicate functions for types
is-fn { }
is-map [&]
is-list []
is-bool $true
is-number (num 0)
is-string ""
▶ $true
lots of things which look like other types are actually strings
is-string 1
is-string {}
▶ $true
likewise, these look like a number and a function, but they are actually strings
is-number 1
is-fn {}
▶ $false
prepends a scalar value to a list
prepend [2 3] 0 1
put [2 3] | prepend (all) 0 1
put 2 3 | prepend [(all)] 0 1
▶ [0 1 2 3]
prepend on strings implicitly transforms to list
prepend ello h
▶ [h e l l o]
appends a scalar value to a list
append [0 1] 2 3
put [0 1] | append (all) 2 3
put 0 1 | append [(all)] 2 3
▶ [0 1 2 3]
append on strings implicitly transforms to list
append hell o
▶ [h e l l o]
concatenate two lists
concat2 [0 1] [2 3]
▶ [0 1 2 3]
concat2 on strings implicitly transforms to list
concat2 he llo
▶ [h e l l o]
removes the element at a given index from a list.
pluck [0 1 x 2 3] 2
put [0 1 x 2 3] | pluck (all) 2
put 0 1 x 2 3 | pluck [(all)] 2
▶ [0 1 2 3]
corner-cases
put [-1 0 1 2 3] | pluck (all) 0
put [0 1 2 3 4] | pluck (all) 4
▶ [0 1 2 3]
pluck on strings implicitly transforms to list
pluck x-men 1
▶ [x m e n]
retrieves the element at index i in a list
get [0 1 s 2 3] 2
put [0 1 s 2 3] | get (all) 2
put 0 1 s 2 3 | get [(all)] 2
▶ s
works on strings, too
get string 0
▶ s
retrieves the first element from a list
first [0 1 2 3]
put 0 1 2 3 | first [(all)]
▶ 0
works on strings, too
first "hello"
first hello
▶ h
nested first
on a list
ffirst [[a b c] 1 2 3]
put [a b c] 1 2 3 | ffirst [(all)]
▶ a
retrieves the second element from a list
second [0 1 2 3]
put 0 1 2 3 | second [(all)]
▶ 1
works on strings, too
second "hello"
second hello
▶ e
drops the first element from a list
rest [0 1 2 3]
put 0 1 2 3 | rest [(all)]
▶ [1 2 3]
works on strings without coercing the result to a list
rest "hello"
rest hello
▶ ello
retrieves the last element from a list (the end of a list)
end [0 1 2 3]
put 0 1 2 3 | end [(all)]
▶ 3
works on strings, too
end "hello"
end hello
▶ o
drops the last element from a list
butlast [0 1 2 3]
put 0 1 2 3 | butlast [(all)]
▶ [0 1 2]
works on strings without coercing the result to a list
butlast "hello"
butlast hello
▶ hell
does whats on the tin
is-empty []
is-empty ''
▶ $true
Works on maps
swap [&a=2 &b=1] a b
▶ [&a=1 &b=2]
Works on lists
swap [b a c] 0 1
▶ [a b c]
Works on strings
tsuff
0
1
returns the nth item in a list
nth [f o o b a r] 3
put f o o b a r | nth [(all)] 3
▶ b
and of course it works with strings
nth foobar 3
▶ b
It returns nothing if the index is out of range
nth [f o o b a r] 10
MATCHES EXPECTATIONS: [nothing]
You can optionally specify the not-found
value
nth [$nil $nil $nil] 10 ¬-found=kaboom
▶ kaboom
It uses drop
under the hood, so negative indices just return the 0-index
nth [f o o b a r] -10
▶ f
this is probably the most interesting function here. it takes input, and if the input is empty, returns whats in the pipe. Otherwise it returns the input, exploded.
check-pipe [1 2 3]
put 1 2 3 | check-pipe []
▶ 1
▶ 2
▶ 3
recursive function which basically performs nested explosions on a list, ignoring lists.
flatten [1 [2 3] [4 [[5 [6] 7]] 8 [] [9]]]
▶ 1
▶ 2
▶ 3
▶ 4
▶ 5
▶ 6
▶ 7
▶ 8
▶ 9
anything else is just returned
flatten foobar
▶ foobar