chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Chicken Gazette - Issue 19


From: Moritz Heidkamp
Subject: [Chicken-users] Chicken Gazette - Issue 19
Date: Thu, 24 Mar 2011 12:30:08 +0100

     _/_/_/  _/        _/            _/
  _/        _/_/_/          _/_/_/  _/  _/      _/_/    _/_/_/
 _/        _/    _/  _/  _/        _/_/      _/_/_/_/  _/    _/
_/        _/    _/  _/  _/        _/  _/    _/        _/    _/
 _/_/_/  _/    _/  _/    _/_/_/  _/    _/    _/_/_/  _/    _/

--[ Issue 19 ]------------------------------------- G A Z E T T E
                               brought to you by the Chicken Team


== 0. Introduction

Welcome to issue 19 of the Chicken Gazette.

== 1. Save The Gazette

As you may have noticed the Gazette hasn't been updated in a while.
This is bad as we feel it is a good way to communicate to the outside
world what's going on inside Chicken and thus would like to keep
it alive. However since it is a volunteer effort it is difficult
to keep the regular schedule up. In order to improve this we need
your help! If you like Chicken and have some spare time on the
weekend, please don't hestitate to contact us through the mailing
list or IRC to get involved in authoring the Gazette. Another way
to help is by contributing tools for automation of the tedious
parts. For more information see Alaric's appeal on the mailing list
(http://lists.nongnu.org/archive/html/chicken-users/2011-02/msg00097.html)
as well as the Gazette wiki page. Thanks!

== 2. The Hatching Farm

The following new extensions were added:

* gts: bindings for the GNU Triangulated Surface library (Ivan Raikov)   
* netstring: parsing and emitting of netstrings                          
  (http://cr.yp.to/proto/netstrings.txt) (Moritz Heidkamp)               
* mongrel2: experimental Mongrel2 (http://mongrel2.org/) handler library
  (Moritz Heidkamp)
* socket: an interface for the BSD socket API (Jim Ursetto)              
* udp6: UDP for IPv6 (Jim Ursetto)                                       
* tcp6: TCP for IPv6 (Jim Ursetto)                                       
* spock: a compiler and runtime system for R5RS in JavaScript            
  environments (Felix Winkelmann)                                        
* simple-sha1: an alternative SHA1 implementation (Felix Winkelmann)     
* medea: a JSON parser based on genturfa'i (Moritz Heidkamp)             
* usage: create CLI usage messages (Mario Domenech Goulart)              
* gazette-tools: automation tools for the Chicken Gazette (Mario         
  Domenech Goulart, Felix Winkelmann, Andy Bennett)                      
* contracts: Design by Contract programming support (Juergen Lorenz)     
* er-macros: syntactic sugar for simplifying ER macro transformer        
  definitions (Juergen Lorenz)                                           
* ssql: SQL as S-expressions. Ported from Chicken 3 (Moritz Heidkamp)    
* feature-test: provides foreign feature testing macros and read-syntax  
  (Jim Ursetto)                                                          
* ssql-postgresql: separated the postgresql transformer from the main    
  ssql egg (Moritz Heidkamp)                                             
* sexp-diff: a port of the Racket library                                
  (http://docs.racket-lang.org/unstable/sexp-diff.html) (Felix           
  Winkelmann)                                                            
* zlib: zlib bindings for Chicken. zlib is a popular data compression    
  library that uses the DEFLATE algorithm internally. It is defined in   
  RFC 1950 (http://tools.ietf.org/html/rfc1950) (Joseph Gay)             
* discount: bindings to the Discount library, which is a                 
  Markdown parser to HTML written in C, (Stephen Eilert                  
  (http://blog.paleolithic-computing.com/))                              
* cvjm : a compiler that translates Java ".class" files into Scheme
  (Felix Winkelmann)
* hen: A beanstalk client (Joseph Gay)                                   

The following new versions have been released:

* utf8 3.3.3: bugfix for string-downcase in turkish locales (Alex      
  Shinn)                                                                 
* bloom-filter 1.1.2: Added chk for fixnum repr overflow when calc     
  `desired-m'. Made `message-digest->integers' only explicit -inline.    
  (Kon Lovett)                                                           
* locale 0.6.9: Added proc `locale-setup' that performs the module     
  init. (Kon Lovett)                                                     
* remote-mailbox-threads 0.0.2: tag version 0.0.2 (compatible with zmq 
  0.1.0) (Moritz Heidkamp)                                               
* message-digest 2.3.3: Add blob as result-form buffer. Rmvd ref to    
  moremacros. Added dep for variable-item. Explicit fx use only. (Kon    
  Lovett)                                                                
* bloom-filter 1.1.3: index list is arg of hasher so no append of      
  sublists. Dropped `numeric-macros' use. Better `desired-m' overflow    
  detection. There is a serious bug somewhere in here or message-digest. 
  (Kon Lovett)                                                           
* matchable 3.0: updating matchable from upstream (Alex Shinn)         
* sxpath 0.1.2: Release sxpath 0.1.2 (Peter Bex)                       
* http-client 0.4.1: release 0.4.1 (Peter Bex)                         
* srfi-19 3.1.2: Fix for date add/subtract duration (actually missing  
  tzi). (current-milliseconds) is not `number'.t (Kon Lovett)            
* postgresql 3.6.3: Tag postgresql 3.6.3 (Peter Bex)                   
* locale 0.6.10: No more `getenv'. Fix for possible non-existent 'TZ'  
  var. (Kon Lovett)                                                      
* message-digest 2.3.4: Use of alt ctx obj (no finalizer use). This is 
  no fix! (Kon Lovett)                                                   
* awful 0.28: releasing version 0.28 (Mario Domenech Goulart)          
* awful-ssl 0.1: releasing version 0.1 (Mario Domenech Goulart)        
* salmonella 1.18: releasing version 1.18 (Mario Domenech Goulart)     
* honu 1.7: 1.7, fixed comment handling (Felix Winkelmann)             
* flsim 1.1: flsim release 1.1 (Ivan Raikov)                           
* sigma 2.3: sigma release 2.3 (Ivan Raikov)                           
* iup 1.0.2: [iup] Tagged version 1.0.2 (Thomas Chust)                 
* netstring 0.0.1: tag 0.0.1 (Moritz Heidkamp)                         
* zmq 0.1.1: tag version 0.1.1 (Moritz Heidkamp)                       
* remote-mailbox-threads 0.0.3: tag version 0.0.3 (Moritz Heidkamp)    
* getopt-long 1.12: getopt-long release 1.12 (Ivan Raikov)             
* cairo 0.1.9: applied patch for parsing options returned by           
  pkg-config - thanks to bpowers (Felix Winkelmann)                      
* mbox 2.2: mbox release 2.2 (Ivan Raikov)                             
* matchable 3.1: fixing record matching (Alex Shinn)                   
* abnf 3.4: abnf release 3.4 (Ivan Raikov)                             
* internet-message 4.3: internet-message release 4.3 (Ivan Raikov)     
* formular 3.4: formular release 3.4 (Ivan Raikov)                     
* bind 0.94: hopefully fixes typedef issue (Felix Winkelmann)          
* formular 3.5: formular release 3.5 (Ivan Raikov)                     
* blas 2.8: blas release 2.8 (Ivan Raikov)                             
* flsim 1.2: flsim release 1.2 (Ivan Raikov)                           
* sqlite3 3.5.2: [sqlite3] Tagged version 3.5.2 compatible with        
  CHICKEN 4.6.5 (Thomas Chust)                                           
* hostinfo 1.4.1: tag 1.4.1 (Jim Ursetto)                              
* sql-de-lite 0.4.4: tag 0.4.4 (Jim Ursetto)                           
* xosd 1.7: uses c-pointer instead of pointer type (thanks to mario)   
  (Felix Winkelmann)                                                     
* http-session 2.5: releasing version 2.5 (Mario Domenech Goulart)     
* static-modules 1.1: static-modules release 1.1 (Ivan Raikov)         
* json-abnf 3.2: json-abnf release 3.2 (Ivan Raikov)                   
* static-modules 1.2: static-modules release 1.2 (Ivan Raikov)         
* miniML 1.2: miniML release 1.2 (Ivan Raikov)                         
* json-abnf 3.3: json-abnf release 3.3 (Ivan Raikov)                   
* simple-sha1 0.1: releasing version 0.1 (Mario Domenech Goulart)      
* usage 0.1: releasing version 0.1 (Mario Domenech Goulart)            
* bind 0.95: fix matching of scope in chunk-repair for typedef-parsing 
  blablablabla (Felix Winkelmann)                                        
* html-utils 0.7: releasing version 0.7 (Mario Domenech Goulart)       
* bind 0.96: handle ___pointer correctly (Felix Winkelmann)            
* easyffi 1.99.6: handle ___pointer correctly (Felix Winkelmann)       
* phricken 1.1: tag 1.1 (Jim Ursetto)                                  
* feature-test 0.1: tag 0.1 (Jim Ursetto)                              
* socket 0.1: tag 0.1 (Jim Ursetto)                                    
* tcp6 0.1: tag 0.1 (Jim Ursetto)                                      
* udp6 0.1: tag 0.1 (Jim Ursetto)                                      
* socket 0.2: tag 0.2 (Jim Ursetto)                                    
* awful 0.29: releasing version 0.29. (Mario Domenech Goulart)         
* contracts 0.1: contracts 0.1 (Felix Winkelmann)                      
* er-macros 0.1: er-macros 0.1 tagged (Felix Winkelmann)               
* system 0.6: bugfix by ckeen (Felix Winkelmann)                       
* lexgen 5.0: lexgen release 5.0 (Ivan Raikov)                         
* lexgen 5.1: lexgen release 5.1 (Ivan Raikov)                         
* abnf 5.0: abnf release 5.0 (Ivan Raikov)                             
* json-abnf 4.0: json-abnf release 4.0 (Ivan Raikov)                   
* internet-message 5.0: internet-message release 5.0 (Ivan Raikov)     
* csv 4.0: csv release 4.0 (Ivan Raikov)                               
* internet-timestamp 3.0: internet-timestamp release 3.0 (Ivan Raikov) 
* smtp 3.0: smtp release 3.0 (Ivan Raikov)                             
* mbox 3.0: mbox release 3.0 (Ivan Raikov)                             
* mbox 3.0: mbox release 3.0 (Ivan Raikov)                             
* formular 4.0: formular release 4.0 (Ivan Raikov)                     
* honu 1.8: fix handling of exponential numbers (Felix Winkelmann)     
* awk 1.4: awk release 1.4 (Ivan Raikov)                               
* readline 1.993: tag 1.993 (Jim Ursetto)                              
* udp 1.15: fixed foreign pointer types to new naming (Felix           
  Winkelmann)                                                            
* nemo 4.4: nemo release 4.4 (Ivan Raikov)                             
* contracts 0.2: added tests by ju (Felix Winkelmann)                  
* flsim 1.3: flsim release 1.3 (Ivan Raikov)                           
* signal-diagram 1.0: signal-diagram release 1.0 (Ivan Raikov)         
* fmt 0.705: tag 0.705 (Jim Ursetto)                                   
* udp 1.16: udp release 1.16 (Ivan Raikov)                             
* spock 0.01: still broken, but at least useful for experimentation    
  (Felix Winkelmann)                                                     
* bind 0.98: rm'd stupid check (thanks to ckeen) (Felix Winkelmann)    
* fmt 0.706: tag 0.706 (Jim Ursetto)                                   
* chicken-doc 0.4.3: tag 0.4.3 (Jim Ursetto)                           
* svnwiki-sxml 0.2.11: tag 0.2.11 (Jim Ursetto)                        
* srfi-27 3.1.3: Bugfix rel for 64-bit fixnum used as rndint bound     
  (not 64-bit fixnum support!) (Kon Lovett)                              
* srfi-27 3.1.4: Fix for wrong state chk in mrg32k3a-pack-state (note  
  that this chk is worthless). Slight mod to mrg32k3a-randomize-state    
  so nxt state is not modulo prev state (simple 16-bit generator was not 
  accurate). No extra chk 32bit value outside of fixnum range in core    
  rndint procs for 64bit machines. Made use of fpremainder explicit (was 
  called fpmodulo but implemented by C lib fmod). (Kon Lovett)           
* awful 0.30: releasing version 0.30 (Mario Domenech Goulart)          
* free-gettext 1.2: replacing last reference to getenv with            
  get-environment-variable (Alex Shinn)                                  
* contracts 0.3: fixed typo in setup script reported by mario; added   
  print->doclist (by ju) (Felix Winkelmann)                              
* spock 0.02: meta-file fix reported by mario (Felix Winkelmann)       
* ezxdisp 2.7: incorrect linker option, reported by David Murray,      
  confirmed by Tim Sally (Felix Winkelmann)                              
* lazy-ffi 1.8.4: added loading srfi-69 as reported by Mehmet Kose     
  (Felix Winkelmann)                                                     
* spiffy 4.12: tag 4.13; the failing salmonella tests due to 'getenv'  
  calls are becoming annoying (Peter Bex)                                
* honu 1.9: allow backslash as operator char (Felix Winkelmann)        
* ncurses 1.5: tag version 1.5 (Moritz Heidkamp)                       
* stalin 0.11.4: fix for #537, thank to sjamaan (Felix Winkelmann)     

== 3. Core development

Peter Bex added tail-pattern support to syntax-rules.  With that Chicken
now fully implements SRFI-46!

Felix Winkelmann added the new top-level command `,m` to csi which allows
you to set the current module. This means you can for example enter `,m
uri-common` and you will be inside the `uri-common` module, i.e. you can
also access bindings which aren't exported by it. This can be handy for
interactively inspecting and debugging modules.

Jim Ursetto's ticket #486 regarding a problem with the `tcp` unit got
fixed. Also, on the experimental branch, Jim's patch attached to ticket
#505 got applied adding the ability to discard input in read-syntax.
This makes it possible to implement something like the `#;` syntax inside
Chicken itself. Cool!

There are two other notable changes on the experimental branch: Chicken
now links with `libpthread` on BSD systems to allow linking other
libraries that are linked with `libpthread` themselves. The other patch
allows using `(const c-string)` as a return type of `foreign-lambda` and
as an argument type for `define-external`.

== 4. Chicken Talk

Attention all Windows users: Matt Welland has built an all-in-one installer
(http://lists.nongnu.org/archive/html/chicken-users/2011-01/msg00158.html)
for your platform. This will make it much easier to sneak Chicken into the
lair of Microsoft. Thanks a lot Matt!

David Dreisigmeyer announced an update of his Chicken REPL for Python
(http://lists.nongnu.org/archive/html/chicken-users/2011-01/msg00179.html)
which is an interesting experiment. Any takers for Ruby?

pmarin asked about an offline version of the manual|
(http://lists.nongnu.org/archive/html/chicken-users/2011-02/msg00001.html)
and it was pointed out that you can either use the manual-labor egg to
build a static HTML version of the manual or download it as a PDF
(http://lists.nongnu.org/archive/html/chicken-users/2011-02/msg00019.html)
from Matt Welland's site.

Another interesting thread was started by
Thomas Hintz about using Amazon S3 with Chicken
(http://lists.nongnu.org/archive/html/chicken-users/2011-02/msg00025.html).
Apparently it is necessary to calculate HMAC-SHA1 signatures to access it
and there is no egg yet to do that. However Thomas said he would create
one as well as an S3 egg when he gets around to it.

Patrick Li tried to implement a `macroexpand-all` function which would
expand forms until there are no macros left in it. Unfortunately it turns
out that this is not possible for the general case with Chicken at the
moment but he ended up with a solution that does as much as is possible
(http://lists.nongnu.org/archive/html/chicken-users/2011-02/msg00058.html).

A longish thread unspun about svnwiki
(http://lists.nongnu.org/archive/html/chicken-users/2011-02/msg00079.html)
started by Paul Nelson. Unfortunately, svnwiki
(http://wiki.freaks-unidos.net/svnwiki/index) has not been ported to
Chicken 4 so far and since Chicken 3 is deprecated Peter Bex advised him
to switch to qwiki instead.

People interested in other programming languages may like Jack Trade's
announcement of the Pointless Programming Language Reference
(http://lists.nongnu.org/archive/html/chicken-users/2011-02/msg00122.html).
It "features 1,875 solutions to 400 common programming tasks in 7
languages" and Chicken is one of them!

Moritz Heidkamp gave a Lisp workshop with a Chicken focus
at the C4 in Cologne, Germany (http://koeln.ccc.de/)
on March 12. A report on it (including the slides used
for the presentation) found in the mailing list archive
(http://lists.nongnu.org/archive/html/chicken-users/2011-03/msg00071.html).
Another event at the same location took place from March 18 to 20 which
was basically a Chicken hacking weekend (as announced on the mailing list
(http://lists.nongnu.org/archive/html/chicken-users/2011-03/msg00022.html)).
Expect a report on that soon!

Tobia Conforto did an informal benchmark of
different programming language implementations
(http://lists.nongnu.org/archive/html/chicken-users/2011-03/msg00070.html)
printing "Hello, world" to standard out with Chicken scoring quite well.
Although it may seem silly at first it makes sense to compare startup
overhead of the different implementations which can be relevant for short
and simple programs.

Mario Goulart announced
(http://lists.nongnu.org/archive/html/chicken-users/2011-03/msg00097.html)
that the directory layout for salmonella results
(http://tests.call-cc.org) and feeds has changed to accommodate
reports for multiple branches, OS platforms and hardware architectures.
Christian Kellermann has been running salmonella on OpenBSD/x86,
using the experimental branch of the chicken-core repository
(http://code.call-cc.org/cgi-bin/gitweb.cgi?p=chicken-core.git;a=shortlog;h=refs/heads/experimental).

On the chicken-hackers
(http://lists.nongnu.org/mailman/listinfo/chicken-hackers) mailing list,
Jim Ursetto resurrected a thread
(http://lists.nongnu.org/archive/html/chicken-hackers/2011-03/msg00002.html)
from 2009 about using the `-j` option for make to build Chicken in
parallel. Jim provided a patch
(http://lists.nongnu.org/archive/html/chicken-hackers/2011-03/msg00010.html)
which seems to work fine. See also ticket #526
(http://bugs.call-cc.org/ticket/526).

Mario Goulart pointed out a symlinking issue
(http://lists.nongnu.org/archive/html/chicken-hackers/2011-02/msg00001.html)
with `libchicken.so` which was affecting cross-compiled Chickens. Mario
also posted a heads-up
(http://lists.nongnu.org/archive/html/chicken-hackers/2011-02/msg00000.html)
regarding to eggs using procedures and type specifier that have been
removed from newer versions of Chicken.  See tickets #507, #508, #509 and
#510.

Still on chicken-hackers and resurrecting topics, Peter Bex re-emerged the
distributed egg repository discussion
(http://lists.nongnu.org/archive/html/chicken-hackers/2011-03/msg00000.html).
Peter has written a detailed document
(http://wiki.call-cc.org/distributed-egg-repos) covering pros, cons, design
goals and description of the system. The mailing list thread is quite long,
with several suggestions and considerations from chicken-hackers
subscribers.

Chicken has been mentioned on a couple of reddit threads recently: 
http://www.reddit.com/r/programming/comments/fvrtr/chicken_portable_efficient_c_compiler_for_the/
and 
http://www.reddit.com/r/scheme/comments/ft2q5/using_scheme_for_practical_projects/

The latter has some kind comments from Zane Ashby
(http://demonastery.org/), who has been blogging about Scheme in general
and Chicken (see Chicken Scheme, and FFI
(http://demonastery.org/52/chicken-scheme-and-ffi/) and Chicken Scheme, and
Web RAD (http://demonastery.org/51/chicken-scheme-and-web-rad/) for
example).

== 5. Omelette Recipes

Some time ago I (Alaric) decided I wanted to produce some syntax diagrams
for Lojban (http://www.lojban.org/), a constructed language I'm
studying. Syntax diagrams make it really easy to see the possible syntactic
structures of things in a language, but are laborious to produce by hand -
I wanted to be able to produce them directly from a grammar. So I produced
banterpixra (which means "language artist" in Lojban; the "er" is
pronounced like in "America" and the "x" is pronounced like a hard h sound,
and you'll probably get it right otherwise). A sample of its output can be
seen online
(http://love.warhead.org.uk/~alaric/junk/lojban-tenses.svg). But I'm not
going to go into much more about banterpixra itself - today, I'm going to
talk about the way banterpixra produces nice vector images: generating SVG
from Chicken Scheme.

I chose SVG as it's probably the easiest vector format to produce from
code, while being widely supported in tools (a growing number of browsers
can display it directly, and Inkscape can be used from the command line to
convert SVG into raster formats such as PNG, as well as being a
full-featured SVG editor and having a standalone SVG viewer).

An SVG file is an XML document describing an image in terms of paths,
filled regions, text, and the like. The full list of capabilities of the is
quite large, but thankfully, the format is being divided into profiles with
optional modules - which means that the SVG Tiny 1.2 specification
(http://www.w3.org/TR/SVGTiny12/) is thankfully readable while providing
most of the tools you could possibly need.

Generating valid XML can be done by pasting strings together, but it's
tedious and error-prone - properly handling all the quoting rules is
difficult, and if you get it wrong, you produce invalid XML in some cases.
Also, if you find yourself wanting to further process the generated XML,
you usually have to parse it again in order to expose the structure of
it beyond a sequence of characters, which is wasteful. So the preferred
technique amongst experienced chicken users is to generate the structure
of the XML as s-expressions using the SXML contentions, then use existing
tools to convert that to XML as a string.

The top-level structure of an SVG document is a simple template we can
wrap around the actual content, given a width and height, like so:

  (define (wrap-svg width height content)
    `(svg (@ (xmlns "http://www.w3.org/2000/svg";)
           (version "1.2")
           (baseProfile "tiny")
           (viewBox ,(sprintf "0 0 ~S ~S" width height)))
        ,@content))

For those not familiar with SXML, what that does is to create a top-level
`<svg>` element with attributes (marked by the address@hidden sublist) setting 
up
an XML namespace, information about the version of SVG in use, and the
"viewbox" that defines the bounding box of the image (in our chosen image
coordinate system). The content, a list of further elements, is then
placed into this element. Rather than specifying `0 0` we could have a
nonzero origin, if we wanted to.

The choice of image coordinate system is largely arbitrary - if we
are drawing a map, we could use kilometres as our coordinates, even
if the entire map then fits into a single kilometre square and all
coordinates are fractional. The viewer will scale the image to fit the
size of the viewing region, with the `viewbox` attribute specified. It
is also possible to work in the coordinate system of the browser (eg,
pixels), and other approaches such as setting up coordinates for physical
media such as standard paper sizes - see section 7 of the SVG spec
(http://www.w3.org/TR/SVGTiny12/coords.html) for details.

The content is, largely, a list of objects (such as lines or filled
polygons). Perhaps the simplest is a rectangle, defined like so:

  (define (make-rect x y w h style)
    `(rect (@ (x ,(number->string x))
            (y ,(number->string y))
            ,@style
            (width ,(number->string w))
            (height ,(number->string h)))))

`style` should be a list of styling attributes, such as `((fill "none")
(stroke-width "1"))` - the full list of styles can be found in section 11
of the specification (http://www.w3.org/TR/SVGTiny12/painting.html).

Text is just a matter of specifying coordinates and styling in attributes,
then the text goes in the element body:

  (define (make-text x y style text)
        `(text (@ (x ,(number->string x))
                  (y ,(number->string y))
                  ,@style)
                ,text))

Check out section 10 of the specification
(http://www.w3.org/TR/SVGTiny12/text.html) for details on text styles.

Drawing lines is interesting. SVG contains an embedded sub-language
for specifying paths, which can be comprised of straight lines, gaps
(eg, the path need not be continuous), and various kinds of curves.
This sub-language is specified in section 8 of the specification
(http://www.w3.org/TR/SVGTiny12/paths.html). Quoting the first example
from the specification, `M 100 100 L 300 100 L 200 300 z` specifies a move
to the position (100,100), then a line to the position (300,100), then
a line to position (200,300), then the end of the path (that's the `z`).
Those are all absolute coordinates - you can also use coordinates relative
to the endpoint of the last operation in the path by using lowercase
letters, although the first operation in the path always needs to be an
absolute movement (`M <x> <y>`) to get started.

This string of path data must then be placed into the `d` attribute of
a `<path>` element, along with styling attributes as per the rectangle
object. It's convenient to represent path data as a list of strings and
numbers, and then convert it into a `<path>` element like so:

  (define (coords-to-path coords)
    (string-join (map ->string coords) " "))
  
  (define (make-line . coords)
    `(path (@ (d ,(coords-to-path coords))
            (stroke-width "1")
            (stroke "black")
            (fill "none"))))

One can then draw an arrowhead from (bx,by) to (bx+dx,by+dy) with a
width of twice w times the length of the arrowhead (eg, set w=0.5 for an
arrowhead that's as wide as it is long, and less for a sharper arrow) like
so:

  (define (make-arrowhead bx by dx dy w)
    (let* ((pdx (* w (- dy)))
         (pdy (* w dx))
         (qdx (* w dy))
         (qdy (* w (- dx)))
         (px (+ bx pdx))
         (py (+ by pdy))
         (qx (+ bx qdx))
         (qy (+ by qdy))
         (tx (+ bx dx))
         (ty (+ by dy)))
    `(path (@ (d ,(coords-to-path
                 (list
                  'M tx ty
                  'L px py
                  'L qx qy
                  'z)))
            (fill "black")))))

It's also possible to create compound objects, which are themselves just
a list of contained objects; this may make the document structure clearer,
as many images are made hierarchially by making objects then joining them
together. Reflecting this structure in the output SVG makes debugging
easier, as you can more easily find your way through the resulting sea
of elements, whether you are viewing the XML directly or opening it in an
editor such as Inkscape. A group is simply a `<g>` element surrounding a
set of objects, so we can make them with a function like so:

  (define (make-group . paths)
    (list (cons 'g (append paths))))

To convert the SXML to XML sent to the current output port, we just need:

  (use sxpath-lolevel)
  (map display
    (flatten
      (sxml:sxml->xml
        (wrap-svg width height content))))

Given all of the above, it becomes easy to generate pictures.

  (define width 100)
  (define height 100)
  (define content (list
                    (make-rect 5 5 90 90 '((stroke "black") (fill "none")))
                    (make-rect 10 10 80 80 '((stroke "black")))))
  (map display
    (flatten
      (sxml:sxml->xml
        (wrap-svg width height content))))

Go, make pretty things!

== 6. About the Chicken Gazette

The Gazette is produced occasionally by a volunteer from
the Chicken community. The latest issue can be found at
http://gazette.call-cc.org or you can follow it in your feed reader at
http://gazette.call-cc.org/feed.atom. If you'd like to write an issue,
consult the wiki (http://wiki.call-cc.org/gazette) for the schedule and
instructions!

[ --- End of this issue --- ]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]