Skip to content

Latest commit

 

History

History
93 lines (69 loc) · 2.2 KB

10-standard-library.md

File metadata and controls

93 lines (69 loc) · 2.2 KB

→ README, → prev: Primitives, Builtins & Prelude, → next: Possible Future Extensions

Standard Library

→ IO, → JSON, → Math, → Str, ...

IO

NB: work in progress.

NB: the io module is built-in (and does not need to be required or used; it can of course still be imported).

>>> "lib/_test.knk" io.contents! 24 [-j)    ; file contents
"\"loading module _test..."
>>> , "lib/_test.knk" io.lines!             ; file lines
>>> , "loading" grep 'say! each
"loading module _test..." say!

JSON

NB: the json module is built-in (and does not need to be required or used; it can of course still be imported).

>>> { x: 42, y: ( 1 2 3 ) } dup json.<-     ; json str <- value
"{\"x\":42,\"y\":[1,2,3]}"
>>> json.->                                 ; json str -> value
{ :x 42 =>, :y ( 1 2 3 ) => }
>>> =
#t

>>> :foo json.<- json.->                    ; kwds become strs
"foo"
>>> x: 42 json.<- json.->                   ; pairs become lists
( "x" 42 )

>>> , :Foo ( :x :y ) defrecord              ; records become dicts
>>> Foo( 1 2 ) json.<- json.->
{ :__koneko_type__ "Foo" =>, :x 1 =>, :y 2 => }

Math

NB: the math module is built-in (and does not need to be required or used; it can of course still be imported).

>>> ( :^ :** :sqrt ) :math use-from

>>> math.pi
3.141592653589793
>>> 1.0 math.exp
2.718281828459045
>>> 10.0 math.log ** round
10

>>> 2 10 ^
1024
>>> 2.0 10.0 **
1024.0
>>> 2.0 0.5 **
1.4142135623730951
>>> 2.0 sqrt
1.4142135623730951

>>> -0.0 math.sign
-0.0
>>> 1.0 0.0 / neg math.sign
-1.0

>>> math.pi 0.5 * math.sin
1.0

>>> :math __module-defs__
( :** :^ :acos :acosh :asin :asinh :atan :atan2 :atanh :cos :cosh :exp :log :pi :sign :sin :sinh :sqrt :tan :tanh )

Str

→ Syntax Highlighted Source, → Function Index

... TODO ...