wiki:LanguageExamples

Kite Examples

Loops

From 1 to 10

(before 1.0a1)

{ value|print; }|for(1|range(10));

(1.0a1 and above)

i = 1; until (i > 10) [ i|print();  i = i + 1; ];

Output:

1
2
3
4
5
6
7
8
9
10

Using keys/values

(before 1.0b1)

var a = ["first":1, "second":2, "third":3];
{ ("The " + key + " number is " + value)|print; }|for(a);

(1.0b1 and above)

import "System.collections";
var a = make System.collections.binary_tree();
a|set("first", 1);
a|set("second", 2);
a|set("third", 3);
a|reset;
var cur = a|cur;
while (not (cur is System.null) or cur|next) [
    cur = a|cur;
    "The %s number is %d"|format([cur.key, cur.item])|print;
    cur = null;
];

Output:

The first number is 1
The second number is 2
The third number is 3

Sockets

Connecting to a server

(before 1.0a1)

var sock = socket|new(socket.AF_INET, socket.SOCK_STREAM, 0);
sock|connect("www.google.com", 80);
sock|write("GET / HTTP/1.0\n\n");
sock|read(8192)|print;
sock|close;

(1.0a1 and above syntax)

import "System.network.socket";
sock = make System.network.socket(System.network.socket.AF_INET, System.network.socket.SOCK_STREAM, 0);
sock|connect("www.google.com", 80);
sock|write("GET / HTTP/1.0\n\n");
sock|read(8192)|print;
sock|close;

Output is similar to:

HTTP/1.0 200 OK
Cache-Control: private
Content-Type: text/html
Server: GWS/2.1
Date: Sun, 18 Feb 2007 20:14:22 GMT
Connection: Close

<html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title> ...