V:4.1.4/Karajan:Kernel Library

From Java CoG Kit

< V:4.1.4(Redirected from Karajan:Kernel Library)
Jump to: navigation, search

 

The Karajan kernel contains a minimum set of elements that are required in order to get the rest of the system running. All kernel elements are automatically available in any program.

Contents

Kernel Constants

kernel:true

true

Represents the true boolean value

kernel:false

false

Represents the false boolean value

kernel:cmdline

cmdline:arguments

Holds a list with the command line arguments (if any)

kernel:user

user.home

Contains the path to the user home directory

kernel:user

user.name

Contains the current user's name

Kernel Elements

kernel:project


kernel:project(stdout)

Aliases: karajan

The root element of a Karajan program. Accepts arguments on the stdout channel and prints them immediately on the console.

kernel:import


kernel:import(file, ...)

Aliases: include

Executes the file specified by the file argument. All arguments received on the default channel are considered to be element definitions (created with export), which import binds to the parent environment, such that after import completes execution, the definitions will be available for use.

foo(
  import("file.k")
) //scope of foo() ends

Import uses the library search path specified in etc/karajan.properties, which defaults to searching the current directory first, then the Java class path. If no file with the given name is found in the library search path, import will fail.

kernel:export


kernel:export(name, value)

Returns the pair (name, value). The value argument should be a lambda, which can be bound by import.

export(foo, element([x], print(x)))

It is also possible for export to be used without arguments, but with a set of immediately enclosed definitions. In this case it would take all the definitions and export them. This makes it easier to have old code somewhat cleanly converted:

export(
  element(x, [], print("x"))
  element(y, [], print("y"))
)

kernel:define


kernel:define(name, value)

Binds a lambda, specified by the value argument to the given name.

kernel:namespace


kernel:namespace(prefix)

Allows the specification of a namespace prefix. Any elements defined in the scope of namespace will automatically have the prefix indicated by the prefix argument, unless another namespace is nested.

kernel:elementdef


kernel:elementdef(type, classname)

Used by the current implementation to map element names to Java implementation classes.

kernel:named


kernel:named(value, *name)

Used internally by the named argument form, but can be used by the user equally well. The following are equivalent:

print("Test", nl = false())
print("Test", kernel:named(name = nl, false())

However, the fact that the *name argument is optional makes it impossible to completely avoid the named form.

If the *name argument is not present, it simply returns the value of the value argument on the default channel.

kernel:number


kernel:number(value)

Can be used with the XML syntax to represent a number. There is no distinction between integral numbers and floating point numbers in Karajan.

kernel:string


kernel:string(value)

Can be used with the XML syntax to represent a string value.

kernel:variable


kernel:variable(name)

Used to represent the value of a variable.

Example:

<set name="n" value="5"/>
<list>
  <number>10</number>
  <string>10</string>
  <variable>n</variable>
</list>

will return the list [10, “10”, 5].

kernel:quotedlist


kernel:quotedlist(...)

Used internally to represent a quoted list. The following two lines of code will produce the same result:

[a, b, c]
quotedlist(a, b, c)

kernel:cache


kernel:cache()

Caches the evaluation of the arguments. Upon subsequent executions of cache, the arguments will not be re-evaluated. Instead, the cached values will be returned. Cache does not make any checks for the invariance of the evaluation of the arguments.

Personal tools
Collaboration and Jobs