Map

What carries over from Python unchanged, what looks the same but is not, and what is new.

Same runtime

Is Koskari a new Python implementation?

No. Koskari runs inside CPython. Numbers, strings, lists, dicts, the builtins, and every module you import are ordinary Python objects. What changes is how you write programs.

So (+ 1 2) is a call to +?

Yes. The first thing inside the parentheses is the callee and the rest are its arguments, the way f(x, y) puts the name first and the arguments in one pair of parentheses. In a .ki file, a line with more than one element is the same call without the parentheses: print "hi" reads as (print "hi").

The shapes, side by side

Python

import os
from os import path

Koskari

import os
import-from os path

Python

obj.attr
obj.method(a, b)
xs[0]

Koskari

obj.attr
(obj.method a b)
xs[0]

Python

x = 6
x = 7
x += 1

Koskari

var x 6
set! x 7
incr! x

Python

if n < 0:
    ...
elif n == 0:
    ...
else:
    ...

Koskari

if (< n 0):
  ...
elif (== n 0):
  ...
else:
  ...

Python

while cond:
    ...

for x in seq:
    ...

Koskari

while cond:
  ...

for-each [x seq]:
  ...

Python

def f(x, y=2):
    return x + y

Koskari

def f [x y: 2]:
  (+ x y)

Python

class C(Base):
    ...

Koskari

class C (Base):
  ...

Python

try:
    ...
except ValueError as e:
    ...

Koskari

try:
  ...
except [ValueError as: e]:
  ...

Python

[1, 2, 3]
(1, 2, 3)
{"a": 1}

Koskari

#[1 2 3]
#(1 2 3)
#{"a": 1}

Looks the same, is not

What looks like Python and is not?

  • A line is one form. print "hi" on its own line is a call. A lone print is the function.

  • var and set!. var introduces a name; set! changes one that exists. Python’s = does both.

  • [a b] is not a list. Square brackets read like parentheses. In def f [x y] they hold the parameters. A list literal is #[...].

  • None and nil. None is Python’s. nil is the empty Lisp list. (None? x) and (nil? x) ask different questions.

  • Truth tests are Python’s. if, while, and cond test Python truthiness, so #[] and 0 are false.

  • Commas are not separators. Whitespace is, and a comma sticks to the token in front of it, so #[1, 2] reads the symbol 1, and the integer 2.

New

What has no Python counterpart?

  • Macros. syntax rewrites code before it runs. See Macros.

  • By-reference parameters. A function can write into its caller’s variable. See Functions and scope.

  • Pairs and quoting. The Lisp list, for macros and code as data.

  • Continuations. Present in the language; not needed on day one.