You are looking at historical revision 8806 of this page. It may differ significantly from its current revision.

The following page is an introduction to Chicken intended to PHP programmers.

This is a work in progress, I will try to work on as frequently as possible (mostly on sunday). In the meantime, feel free to help me by expanding it, correcting (english is not my native language) and/or by commenting on what I have done so far.

Chicken is an implementation of the Scheme programming language which, in turn is a member of the Lisp family of languages. More information about this on the http://schemers.org/ website.

Syntax

Where PHP use the general syntax f(args, ...); , scheme use (f args...)

For example:

substr("abcdef", 0, 2);

is in Scheme:

(substring "abcdef" 0 2)

You will note that:

All scheme expressions use this format, including arithmetic.

The php expression:

3 + 5

Is in scheme:

(+ 3 5)

This is called prefix notation. It may take some time to get used to it but it had several advantages; mostly by avoiding any ambiguity in the operator precedences.

A more complex example can be:

3 + 5 - 12 * 2

Is represented in scheme as:

(- (+ 3 5)(* 12 2))

Variables

Like PHP, scheme does not type variables. If you assign $var to a string, it is a string. you re-assign it to 3, it become a number.

Booleans

TRUE, in scheme, is noted #t while FALSE is noted #f. Unlike PHP, all scheme values are considered to be true (#t) except #f itself, including zero (0), the empty string and others empty structures.

Numbers

All type of numbers are supported by Chicken, including real, complex and rational, natively (without resorting to external libraries).

Number can be expressed in binary, octal, decimal or hexadecimal notation by using the prefixs #b for binary, #o for octal, #d for decimal and #x for hexadecimal. Unprefixed number are deicmal by default (so 21 and #d21 are the same)

PHP scheme
21 #d21
025 #o25
0x15 #x15
n/a #b10101

Strings

Scheme support a vast array of operations on string, including changing case, splitting, extracting substring and regular expressions based searching and replacing

Data structures

The base data structure of PHP is the Array. In scheme it is the list.