CHICKEN for Racket programmers
Warning: This is very much a work in progress!
Running scripts
The first line in a script file meant to be run by the Racket interpreter can either contain a path pointing to the interpreter on your system directly (e.g., #!/usr/bin/racket) or use the env utility to find it:
#!/usr/bin/env racket #lang racket
As Racket is a family of languages rather than just one language, Racket scripts require a second line declaring the language used in the script that follows. In Chicken, such a declaration is not needed.
At the same time, using env as shown above is not a viable solution for Chicken scripts because the Chicken Scheme interpreter (csi) requires the -s option in order to run in script mode rather than in REPL mode. And it seems as if, currently, only GNU env provides a way to run commands with additional arguments form a shebang line.
So, the most straightforward way to get your Chicken scripts to run is simply using the actual path to the Chicken Scheme interpreter on your system. This can easily be found by running command -v csi in a non-interactive POSIX-compatible shell:
$ sh -c 'command -v csi'
Running the shell non-interactively bypasses any existing shell command aliases, which is the desired behavior here.
On a Debian system, the above command returns /usr/bin/csi. On NetBSD, you get /usr/pkg/bin/csi. So, to create a runnable Chicken script on the latter, the first line in the file has to be this:
#!/usr/pkg/bin/csi -s
Should you need your Chicken scripts to be portable, there are also ways to achieve that without using env. See Writing portable scripts.
Procedures
Optional arguments
Named parameters
String handling
Splitting strings
Regular expressions
case
Racket's case expression deviates from the R6RS and R7RS standards in that it uses equal? instead of eqv? to compare data. Because of that, Racket's case can also work with strings:
(let ([str "egg"]) (case str (("egg") #t) (else #f))) ; => #t
As Chicken's case uses eqv?, as defined in the Scheme standard, the same is not possible in Chicken. For simple cases, converting the key into a symbol and then using symbols inside case provides an easy solution to this problem:
(let ([str "egg"]) (case (string->symbol str) ((egg) #t) (else #f))) ; => #t
That said, cond – or match from the matchable egg – provide more reliable and more comfortable solutions for handling strings, especially those containing special characters such as whitespace, non-printables, the vertical bar (|), etc. See the section on symbols in the Chicken Manual for details.