Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
[[toc:]] 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/|http://schemers.org/]] website. == Syntax Where PHP use the general syntax f(args, ...); , scheme use (f args...) For example: <enscript highlight=c> substr("abcdef", 0, 2); </enscript> is in Scheme: <enscript highlight=scheme> (substring "abcdef" 0 2) </enscript> You will note that: * All the expression is enclosed in the parenthesis, not just the arguments * Arguments are separated by spaces, not by commas * The expression is closed by the final closing parenthesis so there is no need for a ; All scheme expressions use this format, including arithmetic. The php expression: <enscript highlight=c> 3 + 5 </enscript> Is in scheme: <enscript highlight=scheme> (+ 3 5) </enscript> 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: <enscript highlight=c> 3 + 5 - 12 * 2 </enscript> Is represented in scheme as: <enscript highlight=scheme> (- (+ 3 5) (* 12 2)) </enscript> == 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. However, it should be noted that Scheme is much stricter when dealing with types. In PHP, you can usually omit typecasts, intermixing data of different types: <enscript highlight=c> 10 + "5" </enscript> Is in Scheme it would cause an error, and you have to explicitly convert a string to a number: <enscript highlight=scheme> (+ 10 (string->number "5")) </enscript> === 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 other empty structures. <enscript highlight=scheme> (if (- 2 2) "hello" "goodbye") ;; "hello" </enscript> === 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 numbers are decimal by default (so {{21}} and {{#d21}} are the same). <table> <tr><th>PHP</th><th>scheme</th></tr> <tr><td>21</td><td>#d21</td></tr> <tr><td>025</td><td>#o25</td></tr> <tr><td>0x15</td><td>#x15</td></tr> <tr><td>n/a</td><td>#b10101</td></tr> </table> === Strings Scheme support a vast array of operations on string, including changing case, splitting, extracting substring and regular expressions based searching and replacing. ==== Exploding and imploding <enscript highlight=c> implode(';', array('a', 'b', 'c', 'd')) </enscript> is in CHICKEN Scheme: <enscript highlight=scheme> (string-intersperse '("a" "b" "c" "d") ";") </enscript> <enscript highlight=c> explode(';', 'a;b;c;d') </enscript> is in CHICKEN Scheme: <enscript highlight=scheme> (string-split "a;b;c;d" ";") </enscript> Please note that the functions {{string-intersperse}} and {{string-split}} are in the {{(chicken string)}} module, so if you are compiling a program, you will need to add this in the beginning of your code: <enscript highlight=scheme> (import (chicken string)) </enscript> ==== Doing several string replacements at once ===== PHP <enscript highlight=c> str_replace(array('PHP', 'Python'), array('Scheme', 'Clojure'), 'PHP and Python are nice programming languages') </enscript> ===== CHICKEN <enscript highlight=scheme> (string-translate* "PHP and Python are nice programming languages" '(("PHP" . "Scheme") ("Python" . "Clojure"))) </enscript> For this, too, you'll need to import {{(chicken string)}}. === Data structures The base data structure of PHP is the array. In Scheme it is the list. However, lists in Scheme are not as versatile as PHP arrays: lists in Scheme are best used for data that is accessed sequentially. So Scheme provides several other data types: vectors (arrays in a usual sense, allowing with a random access by an integer number) and hash tables (allow to access elements by any key).
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 15 to 5?