source: project/wiki/friendly-chicken @ 30887

Last change on this file since 30887 was 30887, checked in by certainty, 7 years ago

friendly-chicken: updated headline and marked eggs and units

File size: 4.6 KB
Line 
1== Friendly CHICKEN
2
3If you're a CHICKEN beginner, you come from another language or a different scheme implementation, there are a few things you might be wondering about, when you're first exposed to CHICKEN. This little tutorial shall help you to lower the barriers and highlight some little pitfalls so that your time with CHICKEN is more fun from the very beginning.
4
5For a general introduction to CHICKEN, see [[man/4/Getting started|Getting started]].
6
7=== The numeric tower
8
9CHICKEN's core does not provide the full numeric tower. This might surprise you if you come from other scheme implementations, or
10use CHICKEN to do your scheme homeworks. Don't worry, your homeworks are safe. It's easy to get the full tower through [[/egg/numbers|the numbers egg]].
11Simply install the egg and load it via '''require-extension''' or '''use'''.
12
13Installation:
14<enscript highligh="scheme">
15$ chicken-install numbers
16</enscript>
17
18Usage:
19<enscript highlight="scheme">
20(use numbers)
21
22(complex? 1.0+2.0i)
23</enscript>
24
25The important thing is that you '''use''' numbers.
26
27=== Where is my fold?
28
29Since scheme is a lisp it offers quite a few useful procedures that operate on lists, such as '''fold''','''unfold''','''filter''' and many more.
30You might have seen those in the examples of a tutorial, textbook or your scheme class. As the happy schemer, that you are, you instantly tried
31them out in a fresh csi session, when you had to realize that CHICKEN doesn't seem to know them.
32
33Again it's easy enough to get it. SRFI-1 comes as a core unit, which means that you don't need to install an egg.
34
35<enscript highlight="scheme">
36(use srfi-1)
37
38(filter odd? (iota 10))
39</enscript>
40
41=== UTF-8
42
43CHICKEN's string procedures generally operate on byte-strings. That means they are not aware of encodings such as UTF-8.
44The following csi transcript shows this:
45
46<enscript highlight="bash">
47CHICKEN
48(c) 2008-2014, The Chicken Team
49(c) 2000-2007, Felix L. Winkelmann
50Version 4.8.4 (rev 3d545a9)
51linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
52compiled 2014-02-06 on dantien (Linux)
53
54#;1> (string-length "λ")
552
56#;2>
57</enscript>
58
59As you see (string-length) on the string containing the unicode-character returns 2 rather than 1.
60To fix this you need to install and use [[/egg/utf8|the utf8 egg]].
61
62See the transcript with utf8 loaded:
63
64<enscript highlight="bash">
65CHICKEN
66(c) 2008-2014, The Chicken Team
67(c) 2000-2007, Felix L. Winkelmann
68Version 4.8.4 (rev 3d545a9)
69linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
70compiled 2014-02-06 on dantien (Linux)
71
72#;1> (use utf8)
73; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/utf8.import.so ...
74; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/chicken.import.so ...
75; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/data-structures.import.so ...
76; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/extras.import.so ...
77; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/regex.import.so ...
78; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/irregex.import.so ...
79; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/ports.import.so ...
80; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/utf8-lolevel.import.so ...
81; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/lolevel.import.so ...
82; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/utf8.so ...
83; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/regex.so ...
84; loading /home/certainty/sys/opt/chickens/master/lib/chicken/7/utf8-lolevel.so ...
85#;2> (string-length "λ")
861
87#;3>
88</enscript>
89
90=== Load useful libraries and units in csi automatically
91
92If you find yourself using these libraries alot you might want to have '''csi''' load them whenever you start it up.
93This can easily be done by adding them to your '''$HOME/.csirc'''.
94
95A sample csirc might look like this:
96
97<enscript highlight="scheme">
98(use number utf8 srfi-1 srfi-13)
99</enscript>
100
101
102=== Other useful eggs and units for real world tasks
103There are some other units and eggs that you might find helpful to solve real world problems with CHICKEN.
104The following lists a few of them:
105
106==== Eggs
107* [[/egg/numbers|numbers]] - Full numeric tower
108* [[/egg/utf8|UTF8]]    - Make string procedures utf8 aware
109
110==== Units
111(You don't need to chicken-install these)
112* [[/manual/Unit srfi-1|SRFI-1]]  - List procedures
113* [[/manual/Unit srfi-13|SRFI-13]] - String procedures
114* [[/manual/Unit srfi-69|SRFI-69]] - Hashtables
115* [[/manual/Unit irregex|irregex]] - Regular expressions
116
117=== Happy Hacking
118
119I hope this little guide helps you to start your CHICKEN journey without too many surprises.
120Have fun hacking ....
Note: See TracBrowser for help on using the repository browser.