1 | == Friendly CHICKEN |
---|
2 | |
---|
3 | If 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 | |
---|
5 | For a general introduction to CHICKEN, see [[man/4/Getting started|Getting started]]. |
---|
6 | |
---|
7 | === The numeric tower |
---|
8 | |
---|
9 | CHICKEN's core does not provide the full numeric tower. This might surprise you if you come from other scheme implementations, or |
---|
10 | use 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]]. |
---|
11 | Simply install the egg and load it via '''require-extension''' or '''use'''. |
---|
12 | |
---|
13 | Installation: |
---|
14 | <enscript highligh="scheme"> |
---|
15 | $ chicken-install numbers |
---|
16 | </enscript> |
---|
17 | |
---|
18 | Usage: |
---|
19 | <enscript highlight="scheme"> |
---|
20 | (use numbers) |
---|
21 | |
---|
22 | (complex? 1.0+2.0i) |
---|
23 | </enscript> |
---|
24 | |
---|
25 | The important thing is that you '''use''' numbers. |
---|
26 | |
---|
27 | === Where is my fold? |
---|
28 | |
---|
29 | Since scheme is a lisp it offers quite a few useful procedures that operate on lists, such as '''fold''','''unfold''','''filter''' and many more. |
---|
30 | You 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 |
---|
31 | them out in a fresh csi session, when you had to realize that CHICKEN doesn't seem to know them. |
---|
32 | |
---|
33 | Again 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 | |
---|
43 | CHICKEN's string procedures generally operate on byte-strings. That means they are not aware of encodings such as UTF-8. |
---|
44 | The following csi transcript shows this: |
---|
45 | |
---|
46 | <enscript highlight="bash"> |
---|
47 | CHICKEN |
---|
48 | (c) 2008-2014, The Chicken Team |
---|
49 | (c) 2000-2007, Felix L. Winkelmann |
---|
50 | Version 4.8.4 (rev 3d545a9) |
---|
51 | linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ] |
---|
52 | compiled 2014-02-06 on dantien (Linux) |
---|
53 | |
---|
54 | #;1> (string-length "λ") |
---|
55 | 2 |
---|
56 | #;2> |
---|
57 | </enscript> |
---|
58 | |
---|
59 | As you see (string-length) on the string containing the unicode-character returns 2 rather than 1. |
---|
60 | To fix this you need to install and use [[/egg/utf8|the utf8 egg]]. |
---|
61 | |
---|
62 | See the transcript with utf8 loaded: |
---|
63 | |
---|
64 | <enscript highlight="bash"> |
---|
65 | CHICKEN |
---|
66 | (c) 2008-2014, The Chicken Team |
---|
67 | (c) 2000-2007, Felix L. Winkelmann |
---|
68 | Version 4.8.4 (rev 3d545a9) |
---|
69 | linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ] |
---|
70 | compiled 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 "λ") |
---|
86 | 1 |
---|
87 | #;3> |
---|
88 | </enscript> |
---|
89 | |
---|
90 | === Load useful libraries and units in csi automatically |
---|
91 | |
---|
92 | If you find yourself using these libraries alot you might want to have '''csi''' load them whenever you start it up. |
---|
93 | This can easily be done by adding them to your '''$HOME/.csirc'''. |
---|
94 | |
---|
95 | A sample csirc might look like this: |
---|
96 | |
---|
97 | <enscript highlight="scheme"> |
---|
98 | (use numbers utf8 srfi-1 srfi-13) |
---|
99 | </enscript> |
---|
100 | |
---|
101 | |
---|
102 | === Other useful eggs and units for real world tasks |
---|
103 | There are some other units and eggs that you might find helpful to solve real world problems with CHICKEN. |
---|
104 | The 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 | |
---|
119 | I hope this little guide helps you to start your CHICKEN journey without too many surprises. |
---|
120 | Have fun hacking .... |
---|