Issue 10

by Mario Domenech Goulart

2010-11-01 +0000

0. Introduction

Welcome to issue 10 of the Chicken Gazette!

1. The Hatching Farm

It has been a fruitful week for the egg repository: three new eggs and lots of bug fixes and improvements.

Moritz Heidkamp has created the zmq egg, which contains bindings for the ZeroMQ library.

Felix Winkelmann has ported Marc Feeley's tar implementation from the Scheme Now (Snow) project to Chicken, available as a chicken egg called .

Alan Post has created the genturfahi egg, a Scheme packrat parser.

Jim Ursetto released chickadee 0.9.8.2, which contains a fix for the iOS 4.1 offset bug.

Felix Winkelmann has added static linking support support for the following eggs: json, base64 and environments.

Peter Bex has fixed a serious issue in Spiffy, the Chicken web server. As Peter noticed in his message to the chicken-users mailing list, earlier versions (i.e., 4.8 and older) are not affected by that bug. Spiffy users are encouraged to upgrade from version 4.9 to 4.10 (which also includes a fix for handling empty path components that are now preserved by uri-generic).

Several eggs have been updated with minor changes: signal-diagram, make, fast-generic, vandusen, html-tags, srfi-27, message-digest, simple-units, error-utils, interval-digraph, getopt-long, format-textdiff, filepath, digraph, moremacros, sigma, nemo, miniML, json-abnf, npdiff, html-form, ext-direct, dict, uri-dispatch, and log5scm.

Several egg authors have adopted the exit status "protocol" for tests with salmonella. The tests are very important for the robustness of eggs and Chicken itself. Since tests are executed by the Chicken core code from the git master branch they also help catching bugs in the compiler. So, adding tests to eggs not only improves the quality of eggs themselves, but the whole Chicken system.

2. Yolklore

Our esteemed team leader and core developer Felix Winkelmann has been put some work on the experimental branch of the git repository for the Chicken core code.

Erik Falor has reported a bug in the build system regarding to the relinking of libchicken, which has been fixed by Felix.

Iruat√£ Souza has contributed a patch for basic proxy authentication for chicken-install.

Alan Post reported a bug which affected optional parameters in lambda lists, which was instantaneously fixed by Felix.

Felix has also added a neat setter for list-ref and fixed some bugs in find-files, delete-directory and blob read-syntax, among other fixes and improvements.

3. Chicken Talk

Some Chicken developers are going to meet during the 5th edition of T-DOSE, a free and yearly event held in The Netherlands to promote use and development of Open Source Software. This year's event will be held on 6 and 7 November 2010 at the Fontys University of Applied Science in Eindhoven. If you plan to go to T-DOSE, visit the Chicken stand to meet Chicken developers and enjoy some Chicken software demonstrations which are planned for the event.

The chicken-users mailing list has been quite active lately.

Christian Kellermann has published the results of a survey he run to find out the platforms used by Chicken users. The survey results publication was followed by even more late results, which showed that some people are running Chicken on ARM architecture.

Felix Winkelmann has started a wish-list page in the Chicken wiki. Users can write there suggestions and things they would like to have in Chicken.

The thread started by Alan Post regarding to using mmap files as strings has continued, with several suggestions and comments. We are glad to have Alan Post back to Chicken development and discussions.

Yi Dai asked about the interaction between the readline egg and procedures line read and friends. Mario Domenech Goulart suggested a hack, but Yi Dai said that he'd like something like Guile's behavior.

Among the usual lurkers and talkative #chicken users, a nice surprise was the presence of Daishi Kato, a long time Chicken user and developer.

4. Omelette Recipes - Tips and Tricks

For this omelette recipe I'll try to follow Jim's mom advice ("write what you know") and show you a little example with a mix of two eggs: awful and sandbox.

awful is a web framework built on top of Spiffy and several web-related Chicken eggs (like http-session and spiffy-request-vars).

The sandbox egg provides a safe evaluation context for basic Scheme expressions.

We're going to implement a very simple web-based Chicken REPL using a sandbox environment for safe evaluation.

The idea is to have a web page with an input box. Users type the forms they want to evaluate and submit them to the server. The server evaluates the given forms in a sandbox environment and return the results.

Here's the commented code:

(use html-tags awful sandbox)

;; Here we define the REPL page.  It uses the session to store the
;; sandboxed environment.  By default, the `main-page-path' parameter
;; value is "/".
(define-session-page (main-page-path)
  (lambda ()

    ;; Create the sandbox environment (if it does not exist yet) and
    ;; store it in the user session.
    (unless ($session 'sandbox-env)
      ($session-set! 'sandbox-env
                     (make-safe-environment
                      parent: default-safe-environment
                      mutable: #t
                      extendable: #t)))

    ;; Here we set an ajax handler for the REPL expressions
    ;; submission.  When users change the REPL input widget (i.e., by
    ;; pressing ENTER), the contents of the text input field are
    ;; submitted and handled by the procedure given as the forth
    ;; argument to `ajax'.
    (ajax "eval" 'repl-input 'change
          (lambda ()

            ;; This binds the variable `repl-input' from the POST
            ;; method the the `repl-input' Scheme variable
            (let ((repl-input ($ 'repl-input)))

              ;; We'd better handle exceptions when trying to
              ;; evaluate the expressions given by users.
              (handle-exceptions
               exn
               ;; If something goes wrong, we print the error message
               ;; and the call chain.
               (<pre> convert-to-entities?: #t
                      (with-output-to-string
                        (lambda ()
                          (print-error-message exn)
                          (print-call-chain))))
               ;; Here we try to evaluate the given expression in the
               ;; sandboxed environment stored in the user session. 
               ;; The `repl-output' page div is updated with the result.
               (<pre> convert-to-entities?: #t
                      (safe-eval
                       (with-input-from-string repl-input read)
                       fuel: 100
                       allocation-limit: 100
                       environment: ($session 'sandbox-env))))))

          ;; Here we pass the contents of the text input to the ajax
          ;; handler.  The default HTTP method used by `ajax' is POST.
          arguments: `((repl-input . "$('#repl-input').val()"))

          ;; The output of the ajax handler updates the `repl-output'
          ;; page div.
          target: "repl-output")

    ;; Here's what is displayed to users
    (++ (<h1> "Sandboxed Chicken web REPL")
        (<input> type: "text" id: "repl-input")
        (<div> id: "repl-output")))

  ;; This tells `define-session-page' to link the page to JQuery
  use-ajax: #t)

To run the code above you'll need to install awful and sandbox:

 $ chicken-install awful sandbox

Then (considering you save the code above in a file called web-sandbox.scm), run:

 $ awful web-sandbox.scm

and access http://localhost:8080.

Here are some screenshots of the code above running on Firefox:

If you try something nasty, the sandbox will abort the evaluation and you'll get an error message and the call chain:

We can also compile the web application:

$ csc -s web-sandbox.scm
$ awful web-sandbox.so

That's awful!

5. About the Chicken Gazette

The Gazette is produced weekly 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, check out the instructions and come and find us in #chicken on Freenode!

The chicken image used in the logo is kindly provided and © 2010 by Manfred Wischner