At the moment, the intent for this project is to add a proper scripting language to [Bim](https://github.com/klange/bim), to which both configuration scripts and syntax highlighting will be ported.
Kuroko, as its name should imply, will also be made available in [ToaruOS](https://github.com/klange/toaruos) as a general-purpose user language, and some utilities may end up being written in it.
Kuroko inherits some core features by virtue of following _Crafting Interpreters_, including its basic type system, classes/methods/functions, and the design of its compiler and bytecode VM.
In a departure from Python, Kuroko has explicit variable declaration and traditional scoping rules. Variables are declared with the `let` keyword and take the value `None` if not defined at declaration time:
Objects and classes in Kuroko work a lot like Python or similar languages in that they have an arbitrary and mutable set of fields, which may be methods or other values.
To create a basic object without methods, the `object` class is provided:
```py
let o = object()
o.foo = "bar"
print o.foo
# → bar
```
To supply methods, define a class:
```py
class Foo():
def printFoo():
print self.foo
let o = Foo()
o.foo = "bar"
o.printFoo()
# → bar
```
The `self` keyword is implicit in all methods and does not need to be supplied in the argument list. You may optionally include it in the method declaration anyway:
```py
class Foo():
def printFoo(self):
print self.foo
let o = Foo()
o.foo = "bar"
o.printFoo()
# → bar
```
When a class is instantiated, if it has an `__init__` method it will be called automatically. `__init__` may take arguments as well.
```py
class Foo():
def __init__(bar):
self.foo = bar
def printFoo(self):
print self.foo
let o = Foo("bar")
o.printFoo()
# → bar
```
Some other special method names include `__get__`, `__set__`, and `__str__`, which will be explained later.
### Collections
Kuroko has built-in classes for flexible arrays (`list`) and hashmaps (`dict`):
Kuroku supports C-style for loops, while loops, and Python-style iterator for loops.
```py
for i = 1, i <5,i =i+1:
print i
# → 1
# 2
# 3
# 4
```
```py
let i = 36
while i > 1:
i = i / 2
print i
# → 18
# 9
# 4
# 2
# 1
```
```py
let l = list()
l.append(1)
l.append(2)
l.append(3)
for i in l:
print i
# → 1
# 2
# 3
```
### Iterators
The special method `__iter__` should return an iterator. An iterator should be a function which increments an internal state and returns the next value. If there are no values remaining, return the iterator itself.
An example of an iterator is the `range` built-in class, which is defined like this:
```py
class range:
def __init__(self, min, max):
self.min = min
self.max = max
def __iter__(self):
let me = self
def makeIter(ind):
let l = me
let i = ind
def iter():
if i >= l.max:
return iter
let out = i
i = i + 1
return out
return iter
return makeIter(self.min)
```
Objects which have an `__iter__` method can then be used with the `for ... in ...` syntax:
```py
for i in range(1,5):
print i
# → 1
# 2
# 3
# 4
```
### Indexing
Objects with the methods `__get__` and `__set__` can be used with square brackets `[]`:
```py
class Foo:
def __get__(ind):
print "You asked for ind=" + ind
return ind * 5
def __set__(ind, val):
print "You asked to set ind=" + ind + " to " + val
let f = Foo()
print f[4]
f[7] = "bar"
# → You asked for ind=4
# 20
# You asked to set ind=7 to bar
```
### String Conversion
If an object implements the `__str__` method, it will be called to produce string values when concatenating or printing.