kaycee tutorial 1 (preview)

back to /kc/docs

hello! welcome to the first part of kaycee's tutorial.
in this article, the following topics will be covered:

  • a hello world program, and its explanation
  • syntactic basics

Hello, World!

a standard "hello world" program in kaycee looks like this:

{$/kc/io}

= ()main $[]
    ["Hello, World!"]println
let's break this down.

the first line, here, imports the io module from the standard library:

{$/kc/io}
kc is the standard library package, which comes pre-installed with kaycee.

the next line looks a bit odd:

= ()main $[]
the first thing that must be understood here is that kaycee uses something called polish notation, or prefix notation; this is opposed to infix notation, which is much more common in most things. where in infix notation you would write 6 - 3 * 4, in polish notation you would write - 6 * 3 4. polish notation eliminates the need for operator precedence rules and grouping with brackets (( and )), which generally results in more concise code.

with this knowledge, it should be pretty clear that what this line is doing is assigning a value to a variable. the syntax for assignment in kaycee is as follows:

= TYPE NAME VALUE
following this rule, the type in the mentioned line is (); in kaycee, (TYPE) is the syntax for writing a function type. if there is no type in the brackets, then that means we are declaring a void function, which returns nothing.

so, we now know that we're declaring a function which returns nothing; what's with the $[]?
in kaycee, function literals are written with a function type followed by a list of arguments enclosed in square brackets, then followed by an expression, like so:

(TYPE)[...] EXPR
so, what's with the $?
$ essentially means "infer type based on context;" here, we have explicitly stated to the compiler in the declaration that we are creating a function which returns nothing, meaning that writing $[] is equivalent to writing ()[]. writing that is also valid, but in declarations like these it is usually fine to allow the compiler to infer.

finally we move on to our last line:

    ["Hello, World!"]println
this calls the print function from the io module we imported from kc earlier.

now, you'll notice this syntax is quite unconventional; where other languages might write print("Hello, World!"), we've written it with square brackets, with the function name at the end.
[b]a is a general interaction syntax; it is used both for calling functions, and indexing ordered structures, such as lists. it looks odd, but you'll get used to it.