tutes-dump/site-tutorials/chicken.html

115 lines
3.8 KiB
HTML

<h1>Using Chicken on SDF</h1>
<div class="intro">
<p>Chicken is a practical implementation of Scheme. Scheme is a programming
language in the Lisp family.</p>
</div>
<h2>Learn</h2>
<p>To learn Scheme programming, check out a tutorial like <a
href="http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html"><cite>Teach
Yourself Scheme in Fixnum Days</cite></a>.</p>
<p>To learn about Chicken, check out the <a href="http://call-cc.org/">Chicken
website</a>, which includes a <a
href="http://wiki.call-cc.org/man/4/The%20User%27s%20Manual">manual</a> and a
<a href="http://wiki.call-cc.org/">wiki</a>.</p>
<h2>Play Around</h2>
<p>To play with Chicken, start the interactive interpreter by running
<kbd>csi</kbd>. It should look like this:</p>
<pre class="screenshot">
$ csi
CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.0
netbsd-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2011-08-24 on ol (NetBSD)
#;1&gt;
</pre>
<p>At the Chicken prompt, you can type in a Scheme program and hit Return to
run your code.</p>
<pre class="screenshot">
#;1&gt; (print "Hello, World")
Hello, World
#;2&gt;
</pre>
<h2>Install Eggs</h2>
<p>The Chicken community produces third-party libraries called <dfn>eggs</dfn>.
(If you're familiar with the Ruby programming language, eggs are like Ruby's
gems.) As an example, let's install the <a
href="http://wiki.call-cc.org/eggref/4/readline">readline</a> egg. This will
allow you to use in the Chicken interpreter the same editing and history
commands you use in your shell. For example, hitting the Up key will enter your
previous command.</p>
<p>Ideally, you could just run <kbd>chicken-install readline</kbd> and the egg
would be installed. But if you do that, you'll get an error. Since you don't
have administrator privileges on SDF, you can't install eggs to the default
location (a system directory). You must install the eggs in your home
directory, which requires you to do a little configuration beforehand. I'll
show you how to do that.</p>
<p>I'll assume you're running Bash as your shell and that you want to keep
Chicken-related files in ~/chicken. First create a directory for a Chicken
repository:</p>
<p class="kbd"><kbd>mkdir -p ~/chicken/lib/chicken/6</kbd></p>
<p>Then install the repository:</p>
<p class="kbd"><kbd>chicken-install -init ~/chicken/lib/chicken/6</kbd></p>
<p>Then create some environment variables so Chicken will know to use your new
repository for eggs, and will compile against SDF's system libraries when
installing eggs:</p>
<p class="kbd"><kbd>export CHICKEN_INCLUDE_PATH=${HOME}/chicken/lib/chicken/6<br>
export CHICKEN_REPOSITORY=${HOME}/chicken/lib/chicken/6<br>
export CSC_OPTIONS="-I/usr/pkg/include -L/usr/pkg/lib -static-libs"</kbd></p>
<p>(You may also wish to put the above lines in a shell startup file, like
~/.bash_profile, so that the variables will be set every time you log in to
SDF.)</p>
<p>Now you can install the readline egg:</p>
<p class="kbd"><kbd>chicken-install readline</kbd></p>
<p>If the install was successful, we can check whether everything's working.
Start the Chicken interpreter with <kbd>csi</kbd> and run this Scheme program
to load the readline egg:</p>
<p class="kbd"><kbd>(use readline)</kbd></p>
<p>Then run this program to use readline in this interpreter session:</p>
<p class="kbd"><kbd>(current-input-port (make-gnu-readline-port))</kbd></p>
<p>Now check if you have readline support in the interpreter. Run a trivial
program like <kbd>42</kbd> and then hit the Up key and check if "42" gets
entered at the prompt. If so, the readline egg is installed and working. You
can put the first two Scheme programs (the ones that load the egg and make it
work) into a ~/.csirc file and the interpreter will run those programs at the
beginning of each session.</p>
<hr>
<p>$Id: chicken.html,v 1.15 2011/08/29 06:43:41 ab9 Exp $</p>