source: project/gazette/src/issues/16.wiki @ 21997

Last change on this file since 21997 was 21997, checked in by Moritz Heidkamp, 10 years ago

gazette #16: `use' is not available in empty modules

File size: 8.0 KB
Line 
1((title . "Issue 16")
2 (authors "Christian Kellermann" "Moritz Heidkamp")
3 (date . 1292360179))
4
5== 0. Introduction
6
7Welcome to the belated issue 16 of the Chicken Gazette.
8
9== 1. The Hatching Farm
10
11It has been a bit quiet in the egg repository apart from
12[[user:kon-lovett|Kon Lovett]] releasing a new version of the
13[[egg:lookup-table|lookup-table egg]].  [[user:alyn.post|Alan Post]]
14has been busy getting his [[egg:genturfahi|genturfa'i egg]] into
15shape. [[user:mario-domenech-goulart|Mario Goulart]] has ported the
16[[egg:statvfs|statvfs egg]] to chicken 4.
17
18== 2. Core development
19
20In the {{experimental}} branch of the [[http://code.call-cc.org|code
21repository]] several bugs have been fixed this week:
22
23* [[ticket:438|Ticket #438]]: Makefile's clean target removed generated setup-api
24  DISTFILEs which is not acceptable.
25
26* [[ticket"340|Ticket #340]]: (Spiffy hangs occasionally (again!)) has been closed
27  since it seems that the fixes introduced in the {{safer-scheduler}}
28  branch are fixing (or hiding) the problem. Additionally Peter fixed
29  a couple of bugs in the openssl bindings.
30
31* [[ticket:424|Ticket #424]]: (umask support) our first change request has been accepted!
32
33* [[ticket:447|Ticket #447]]: Inconsistencies when calling set-finalizer! multiple
34  times have been found by [[user:moritz-heidkamp|Moritz Heidkamp]]
35  and fixed by [[user:felix-winkelmann|Felix Winkelmann]]. Finalizers
36  are scanned first and then marked to make sure the first mark will
37  trigger the finalizer of the object.
38
39* [[ticket:444|Ticket #444]]: Symbol lookup fails in modules in conjunction with
40  renaming macros: [[user:peter-bex|Peter Bex]] came up with a patch
41  to fix this bug which turned out to be of a more general nature than
42  just affecting the IR-macro expander.
43
44Also chicken now has another scrutinizer mode called
45{{-picky}}. ''When given, the scrutinizer warns about undefined
46branches in conditionals in tail-position of global procedures that do
47not perform a self-call.'' as Felix explains on
48[[http://www.mail-archive.com/chicken-users@nongnu.org/msg12765.html|chicken-users]]
49
50The debug switch ''-:d'' is now also handed to the ''chicken'' program
51by the compiler driver ''csc''.
52
53And we welcome back our lambda lifting code which has been put back
54into the experimental branch by Felix.
55
56== 3. Chicken Talk
57
58But alas, this has also been bug finding week! [[user:alyn.post|Alan
59Post]] as well as Moritz and Peter stumbled over some strange findings
60during the last week. Alan's [[egg:genturfahi|genturfa'i]] egg somehow
61caused the compiler to create huge amounts of code as you know from
62[[issues/15.html|last week's]] issue. This week Alan wanted to check
63for common subexpression in his data and
64[[http://www.mail-archive.com/chicken-users@nongnu.org/msg12731.html|compared
65the whole list with equal?]] which contained in his case circular
66defined procedures. Equal? traversed these structures blowing up the
67heap. If you are interested in the process of this issue follow
68[[ticket:440|ticket #440]].
69
70[[user:sven-hartrumpf|Sven Hartrumpf]] pointed out a problem in the
71handling of a huge number of
72[[http://www.mail-archive.com/chicken-users@nongnu.org/msg12740.html|command
73line arguments]], which Felix fixed in the {{experimental}} branch.
74
75David Dreisigmeyer has been running into problems with the
76[[egg:bind|bind egg's]]
77[[http://www.mail-archive.com/chicken-users@nongnu.org/msg12761.html|parser]]
78that still have to be resolved.
79
80Apart from other smaller questions to the list we have experienced an
81outtake of the chicken-users mailing list due to the recent hack at
82GNU's savannah site. In the meantime FSF's admin have been able to
83restore the list and its archives to full functionality. Thanks for
84that. If the main archive at nongnu.org is not available you can use
85mirrors of this archive at
86[[http://www.mail-archive.com/chicken-users@nongnu.org/|mail-archive.com]].
87
88== 4. Omelette Recipes
89
90This week I'd like to give you a brief introduction to
91[[http://wiki.call-cc.org/man/4/Modules|Chicken's module system]]. Modules
92form a ''namespace'' or ''environment''. Basically you can think of
93modules as containers for bindings. Also you have full control over
94which bindings are exported from a module. This way you don't have to
95worry about polluting the global namespace with auxiliary bindings. No
96silly name prefixes anymore! An example illustrates this best:
97
98<enscript language="scheme">
99(module palindrome
100
101(palindromify palindrome?)
102
103(import chicken scheme extras srfi-13)
104
105(define max-length 100)
106
107(define (palindromify s)
108  (string-append s (string-reverse s)))
109   
110(define (palindrome? s)
111  (let* ((len (string-length s))
112         (half (quotient len 2)))
113    (cond ((> len max-length)
114           (error 'palindrome?
115                  (format "palindromes may not be longer than ~A characters" max-length)))
116          ((odd? len)
117           (palindrome? (string-append (string-take s half)
118                                       (string-drop s (+ half 1)))))
119          (else (string=? (string-reverse (string-take s half))
120                          (string-drop s half))))))
121)
122</enscript>
123
124As you can see, it's pretty straight forward. Unsurprisingly, the
125{{module}} form introduces a module definition. The first symbol
126{{palindrome}} is the module's name, followed by a list of symbols to
127be exported from the module: {{(palindromify palindrome?)}}. These
128symbols have to be bound somewhere inside the module. The rest of the
129form is regular Scheme establishing these bindings. The first thing we
130have to do is {{(import chicken scheme srfi-13)}}. Yes, this means a
131module's environment is completely blank initially (except for the
132{{import}} form) thus we even have to import {{scheme}},
133yet! This is an especially nice way to create an environment for a
134DSL: No regular Scheme bindings are going to get in your way. In our
135case we stick to Chicken flavored Scheme and some SRFI-13 goodness to
136define a few palindrome procedures. Note that we define a
137{{max-length}} of 100 characters inside our module without exporting
138it. This means users of our module will not be able to touch that
139limit. Further note that code inside the {{module}} form is not
140indented since usually there's only one module definition spanning the
141whole file.
142
143How to use this module now? Well, just import it like any other
144module. Try sticking the above code into a {{palindrome.scm}} file,
145{{load}} it in a {{csi}} REPL and then {{(import palindrome)}}:
146
147 #;1> (load "palindrome.scm")
148 ; loading palindrome.scm ...
149 #;2> (import palindrome)
150 #;3> (palindrome? "chicken")
151 #f
152 #;4> (palindromify "fo")     
153 "foof"
154 #;5> (palindrome? (palindromify "fo"))
155 #t
156 #;6> max-length
157 
158 Error: unbound variable: max-length
159
160
161See, no rocket science in that, though some basic linguistics. The
162best thing is that the modules we imported into our {{palindrome}}
163module are not visible in the environment our module is imported
164into. So if our REPL environment hadn't {{srfi-13}} imported before
165importing our module, it still won't have it afterwards. Nice!
166
167One thing that might cause confusion is that Chicken eggs are not
168equal to modules, although many eggs consist of just one module. The
169difference is that eggs may contain any kind of Chicken Scheme code,
170be it only one module, many modules, one or more programs or just some
171raw definitions. It's all up to the egg author. Then you have
172accompanying egg specific forms like {{require-library}} which loads a
173module from an egg and {{use}}/{{require-extension}} which load and
174then import egg modules. How these are used and how eggs are built is
175beyond the scope of this recipe but you may want to check out
176[[http://wiki.call-cc.org/eggs%20tutorial|the eggs tutorial on the wiki]].
177
178== 5. About the Chicken Gazette
179
180The Gazette is produced weekly by a volunteer from the Chicken
181community. The latest issue can be found at
182[[http://gazette.call-cc.org]] or you can follow it in your feed
183reader at [[http://gazette.call-cc.org/feed.atom]]. If you'd like to
184write an issue, [[http://wiki.call-cc.org/gazette|consult the wiki]]
185for the schedule and instructions!
Note: See TracBrowser for help on using the repository browser.