2008-11-24

Simple GnuPLoTting

gnuplot is a very powerful and widely used interactive data plotting program. It can generate two-dimenational and three-dimensional surface plots, either on screen or print to files with a wide-array of supported formats. If you are not familiar with it, you can get an idea of its capabilities here
A new package, gnuplot.plt, is now available on planet which allows you to programmatically interact with gnuplot processes and generate plots on the fly. The package provides a simple interface that abstracts gnuplot's quirky syntax and takes care of data marshalling using temporary files.
Without further ado, here is to every computer scientist's favorite growth curves:

(require (planet vyzo/gnuplot))
(define gplot (gnuplot-spawn))
(define data 
  (gnuplot-data
   (build-list 90
     (lambda (x) 
       (let ((x (add1 (/ x 10.))))
         (list x (log x) (* x (log x)) (expt x 2) (expt 2 x)))))))
;; png output options
(define png '(png enhanced transparent font (str arial)))
;; on screen plot
(gnuplot-set gplot '(title (str "growth curves")))
(gnuplot-plot gplot 
  #:range '(() (1 1000))
  (gnuplot-item data '(using (seq: 1 1) title (str "x") with line))
  (gnuplot-item data '(using (seq: 1 2) title (str "log(x)") with line))
  (gnuplot-item data '(using (seq: 1 3) title (str "xlog(x)") with line))
  (gnuplot-item data '(using (seq: 1 4) title (str "x^2") with line))
  (gnuplot-item data '(using (seq: 1 5) title (str "2^x") with line)))
;; replot to png
(gnuplot-hardcopy gplot "/tmp/grow.png" #:term png)
;; redo with logscale
(gnuplot-set gplot '(logscale y))
(gnuplot-replot gplot)
(gnuplot-hardcopy gplot "/tmp/loggrow.png" #:term png)

2008-11-21

PLT Scheme v4.1.3

PLT Scheme version 4.1.3 is now available from

  http://plt-scheme.org/
This is a bug-fix release. Notable changes:
  • Web Server:
    • Documentation rewritten to separate servlet APIs and server extension APIs
    • HTTPS supported on the "plt-web-server" command-line with "--ssl" option
    • Stateless servlets supported in default configuration through 'stateless interface-version
    • `web-server/servlet-env' supports top-level servlets through #:servlet-path
    • Servlets are served from anywhere in the htdocs directory by default
    • A template system based on the Scribble syntax has been added, see web-server/templates in the documentation
    And many other internal modifications to make extension easier!
[Note that mirror sites can take a while to catch up with the new downloads.] Feedback Welcome.

2008-10-28

PLT Scheme version 4.1.2 is now available from

  http://plt-scheme.org/
This is a bug-fix release. [Note that mirror sites can take a while to catch up with the new downloads.] Feedback Welcome.

2008-10-06

Web Application Development in PLT Scheme

Many users often post to the plt-scheme mailing list asking for introductions to Web application development in PLT Scheme. They've heard of the continuation-based PLT Web Server and want a gentle introduction. Unfortunately, there has been a distinct lack of good documentation and tutorials for the server. Taking the cue from two users: Jens Axel Soegaard and David Reynolds, we've written a tutorial with Danny Yoo.

The tutorial is available at http://docs.plt-scheme.org/continue/index.html. It walks through the creation of a blog application, introducing features slowly and culminates in an SQL-backed database for the posts. Of particular interest, is the fast start servlet setup based on the Instaservlet package from Untyped.

Please take a look and pass along this as a pointer to those who may be interested in PLT Scheme.

2008-10-05

PLT Scheme v4.1.1

PLT Scheme version 4.1.1 is now available from

  http://plt-scheme.org/
Notable changes:
  • web-server: New servlet development tutorial; quick launching of servlets from DrScheme via the `web-server/insta' language; new form abstraction through formlets.
  • misc: mzc can "decompile" bytecode files; `#lang' lines wired to the top of DrScheme's definition window; improved searching in DrScheme; some foreign interface extensions.
[Note that mirror sites can take a while to catch up with the new downloads.] Feedback Welcome.

2008-08-12

PLT Scheme v4.1

PLT Scheme version 4.1 is now available from

  http://plt-scheme.org/
  • DrScheme changes:
    • The Module language now has an automatically inserted #lang declaration, so the interactions window is available right away for new windows.
    • Searching is now interactive (see the manual for details).
    • Memory limits are now enabled by default.
  • Typed Scheme supports a novel type checking mechanism for homogeneous and heterogeneous variable-arity function definitions and applications.
  • Redex (a domain-specific language for testing operational semantics) is now included in the distribution. See also redex.plt-scheme.org.
  • Lots of improvement to the documentation, including: better searching, table-of-contents, and language-sensitive help (in the teaching languages).
  • The world.ss teachpack no longer supports end-of-time, only stop-when.
  • MzScheme has now a logging facility, search the documentationfor "logger" for more details.
  • Bug fixes:
    • begin in R5RS (and derived languages),
    • #lang planet,
    • eval works with phases.
Feedback Welcome.

2008-07-29

Search in DrScheme

I've just overhauled search in DrScheme. Instead of popping up a dialog box and asking you for a search string, you get a new editor along the bottom of the DrScheme window where you can type a search string and DrScheme responds by circling (in purple) all of the occurrences of the search string in the file, both in the main window and in the contour window.

From there, you can use the new menu shortcuts to navigate forwards and backwards through the hits, optionally replacing occurrences of the search string with the replace strings (see the Edit menu).

With the default settings, typing a search string does not move around in the main window. Specifically (unlike Emacs, Safari, or Firefox), you don't move immediately to the first occurrence of the search string. You have to hit return or one of the search keys (in the Edit menu) for that to happen. But you can enable this in the General pane of the Editing tab in the preferences dialog. Click on "Search using anchors". Now, when you search for a string, DrScheme will whizz you right to it and when you edit the search string, DrScheme will shift the insertion point based on the search string. In order for you to keep track of where edits will go, you'll see a funny looking little red dongle in your text. That's where the insertion point was when you started your search, and that's where DrScheme starts all of these implicit searches from.

Try it out and let us know what you think! In particular, is the anchor-based search or the non-anchor-based search more intuitive for you?

2008-07-04

PLT Scheme version 4.0.2 is now available from

  http://plt-scheme.org/
This release fixes a bug that caused PLaneT packages to install abnormally slow in 4.0.1. [ For those that use the nightly builds, subversion, or 4.0.1tsrj2008, you already have this fix (and even more fixes). You do not need to upgrade. The version in svn is now 4.0.2.3 to minimize confusion. ] Feedback Welcome.

2008-06-22

PLT Scheme v4.0.1

PLT Scheme version 4.0.1 is now available from http://plt-scheme.org/ This release fixes a number of bugs. Most noteworthy, the "Internal Error" message when requiring a PLaneT package has been fixed and user-defined teachpacks now work properly. Feedback Welcome.

2008-06-12

PLT Scheme version 4.0 is now available from

http://plt-scheme.org/
This major new release offers many improvements over version 372, and we encourage everyone to upgrade.
  • The PLT Scheme language now provides better syntax for modules, better support for optional and keyword arguments to functions, a more complete syntax for structure types, new syntax for list comprehensions and iterations, a more complete and consistent set of list operations, a more complete set of string operations, and streamlined hash-table operations.
  • The documentation has been re-organized and re-written. New tutorials and overviews offer a clearer introduction to Scheme and PLT Scheme.
  • New documentation tools help programmers create and install documentation for libraries and Planet packages. All installed documentation can be read though the user's web browser, and even searching within the browser works on local files.
    The language for writing documentation is an extension of Scheme, and document sources are linked to implementations through the module system. The module connection allows, for example, reliable automatic hyperlinking of identifiers mentioned in documentation to their specifications in other documentation.
  • R6RS programs are supported in two ways: though the plt-r6rs executable and through the #!r6rs prefix. The latter allows an R6RS library or program to serve as a PLT Scheme module.
  • Legacy R5RS support is improved, partly through a separate plt-r5rs executable.
  • Pairs are immutable within the PLT Scheme language; mutable pairs (which are the same as R6RS and R5RS pairs) are provided as a separate datatype. For more information, see “Getting rid of set-car! and set-cdr!
  • ProfessorJ uses a new and improved parser, it evaluates programs faster, and it includes a Java-specific indenter.
  • Testing frameworks for the HtDP and HtDC (ProfessorJ) teaching languages have been unified. Both support systematic unit testing in a comprehensive fashion. When programs lack tests, students are asked to add test cases. When all tests succeed, a simple message says so; otherwise, a pop-up window (dockable) displays URLs to the failed test cases and explains why the cases failed.
  • Typed Scheme, a statically typed dialect of Scheme, is now included with PLT Scheme. While Typed Scheme is still in its early stages of development, it supports modular programming with types and full interaction with existing untyped code. Safe interactions between typed and untyped modules are enforced via contracts. Typed Scheme also features a novel type system designed to accommodate Scheme programming idioms. For more information, see the Typed Scheme page.
Feedback Welcome.

2008-06-06

The Tour in Video

Putting behind its stodgy textual past, the DrScheme tour is now in video! It's rather preliminary, and can use lots of improvement, but now we're really taking it to the kids.

2008-06-03

PLT Scheme version 4.0 is Coming Soon

PLT Scheme is now 13 years old. The initial version was little more than glue code between a few open-source libraries, which seemed to offer the quickest solution to our modest goals. Modest success leads to bigger goals, however, and then continued success leads to ever more ambitious goals. Before you know it, a mass of users, co-developers, libraries, and documentation rely on design decisions that were made for a much smaller project years before.

Naturally, many of those early design decisions turn out to be a poor fit for the project’s eventual role. Starting from scratch isn’t usually practical, so you gradually adjust the infrastructure to meet new needs. That was precisely the story for the version 300 series of releases for PLT Scheme. The biggest gap between our original and current goals was in run-time performance, so we replaced bytecode interpretation with a just-in-time native-code compiler, and we replaced a memory manager based on “conservative” estimates of pointer usage with one that uses precise information.

Performance improves a bit more with version 4.0, but mostly we’ve moved on to a bigger mismatch between the original and current goals: the way that PLT Scheme presents itself to users. PLT Scheme was originally conceived as R5RS Scheme with some extensions to make it practical, and with useful tools (notably an IDE) and libraries (notably a GUI library) built on that core. Our documentation and web pages reflected that architecture – which now seems completely upside-down.

Version 4.0 is a fresh start in the way that we present PLT Scheme. It’s a new language. PLT Scheme is a dialect of Scheme, certainly, but it’s not merely a superset of R5RS, R6RS, or other standards, and those standards are not really the best place to start understanding PLT Scheme. At the same time, the unique extensibility features of the PLT Scheme language and tools allow them to support other languages easily, including R5RS (though a new plt-r5rs executable), R6RS, and more.

Improvements to the PLT Scheme language include better syntax for modules, better support for optional and keyword function arguments, more expressive syntax for structure types, streamlined hash-table operations, new syntax for list comprehensions and iterations, a more complete and consistent set of list and string operations, and reduced dependence on mutable pairs. To current users of PLT Scheme, these changes will seem like the big ones behind version 4.0, but they’re small compared to the overall re-organization and the accompanying documentation effort.

We wrote hundreds of pages of new documentation, including much more tutorial and overview information. We ported hundreds of pages of existing documents to new a system that produces cleaner, better organized, more consistent output. We will replace the old tangle of web pages (that try to explain a confusing federation of tools) with a simple page about “PLT Scheme.” We have even streamlined the command-line flags for the main virtual machine.

The development of PLT Scheme version 4.0 took about one year of hard work. In retrospect, that doesn’t sound too bad, considering the scale of the existing code base, the number of things that we improved, and the total size of the documentation (about 2000 pages in PDF form). Still, you can imagine how happy we are to arrive at a stable release, and we hope that the improvements in PLT Scheme version 4.0 work as well for everyone else as they do for us.

For a preview, see http://pre.plt-scheme.org/. The final version 4.0 release is just days away.

2008-02-23

Dirty Looking Hygiene

With the recent release of Arc, there has been some discussion over hygienic macros. Yes, hygienic macros are usually very convenient, but they can become messy in some ‘corner’ cases. People who learn about macros in Scheme usually start with syntax-rules, and being the limited tool that it is, they often get the impression that for advanced uses (like a macro that captures an identifier) you need to use syntax-case which is this “really obscure thing”. For example, say that we want to implement an if form that is similar to Arc's if. This is pretty easy using syntax-rules:

  (define-syntax if*
    (syntax-rules ()
      [(if*) (void)]
      [(if* X) X]
      [(if* C X more ...) (if C X (if* more ...))]))
But more important than being easy to write: it is also easy to read. In fact, the nice thing about syntax-rules is that you write more or less the specification of your transformation. Compare this to the specification of Arc's if, which appears in a comment before the definition of ac-if in “ac.scm”:
  ; (if) -> nil
  ; (if x) -> x
  ; (if t a ...) -> a
  ; (if nil a b) -> b
  ; (if nil a b c) -> (if b c)
(Except that the comment mixes up the syntactic specification and the semantic evaluation.) As a side note, now that we have this definition, it is easy to construct a new language that is just like MzScheme, except for its if that behaves like the above:
  (module arc-like mzscheme
    (define-syntax if* ...the above definition...)
    (provide (all-from-except mzscheme if)
             (rename if* if)))
You can now write code that uses "arc-like.scm" as its language, using the new if. There is no problem in accommodating two languages with two different if's: the new form is compiled to the old one, and there is no confusion in which version you use in any module. Back to the macro issue: as I said above, you run into problems if you want to capture names, right? For example, if you want to implement Arc's aif. The usual syntax-case solution is to construct an identifier that has the lexical context of the input syntax. It's easy to abstract over all this — I posted a message on the Arc forum showing how to define a defmac macro that has the simplicity of syntax-rules with the added convenience of specifying keywords and captured names. This works for some cases, but there are still some subtle corner cases. But there's a better solution in PLT Scheme, one that follows Paul Graham's intuition when he says:
“captured symbols are kind of freaky”
The basic idea is a change of perspective: instead of (unhygienically) binding individual occurrences of it whenever aif is used, you define it once as a thing in its own right — a special context-dependant piece of syntax. Outside of an aif form, it has no meaning: we simply make it throw a syntax error. Uses of aif provide a meaning for it by locally changing its meaning (its expansion) to something useful: the binding that holds the result of evaluating the condition expression. (“Locally” means within a piece of syntax, so the new meaning is valid in a lexical-scope.) In PLT Scheme, the “special context-dependant piece of syntax” are syntax parameters, and you change them locally with syntax-parameterize. To continue the above example, here's how we make our if* anaphoric:
  • require the (lib "stxparam.ss" "mzlib") library,
  • define it as a syntax using define-syntax-parameter, and have it raise an error by default,
  • bind a temporary variable to the result of evaluating the condition,
  • wrap the positive branch with syntax-parameterize, using make-rename-transformer, which is a convenient way to make a macro that behaves like the new variable.
The implementation looks like this:
  (require (lib "stxparam.ss" "mzlib"))
  (define-syntax-parameter it
    (lambda (stx)
      (raise-syntax-error #f "can only be used inside `if'" stx)))
  (define-syntax if*
    (syntax-rules ()
      [(if*) (void)]
      [(if* X) X]
      [(if* C X more ...)
       (let ([b C])
         (if b
           (syntax-parameterize ([it (make-rename-transformer #'b)]) X)
           (if* more ...)))]))
The resulting macro does not break hygiene. For example, (let ([it 3]) (if #t it)) evaluates to 3, because it shadows the global it that if changes. This is a change from a real unhygienic macro — but that's the whole point: we (the macro author) do not interfere with scopes in the user code. Note that (if 1 (if 2 it)) still evaluates to 2, because the outer if does not really bind it — it is not captured, just changed locally — so the inner if changes it again. Also, (if #f it it) raises the usual context error, since our macro changes it only in the positive branch.

2008-01-14

A Privacy Flaw, Thwarted

My student Brendan Hickey recently identified the following security hole.

A university (let's call it Orange University) wants to let its graduating students vote on their graduation speaker. They used to do it by paper; catching up with the times, they now do it on the Web.

They used to have a box into which you could type the name of your nominee. But that is surely problematic: people misspell names, you have to argue about how to count ambiguous votes, someone will vote for their pet bonobo, etc. Better (perhaps) to give them the names of all the students and let them choose. [Alert: if Orange U adopts a simple naming scheme for email addresses, a student can immediately screen-scrape a pretty plum list to sell a spammer. Brendan and I noticed this in a femtosecond; I don't know why this didn't occur to the university.]

Anyway, now you have a Web page where people are going to choose, and the software that processes the responses must distinguish between these choices. You have to associate a key with each student. You've already got a key for each candidate: their student ID number. So you use that as your key. Now anyone viewing the page source can immediately see which student ID number goes with which student name. So much for confidentiality.

Whoops.

I'd like to point out that Pete Hopkins's send/suspend/dispatch, and the improved version of it by Jay McCarthy, identify and solve just this code structuring problem in a way that the privacy leak can never occur. For the most up-to-date presentation of it, read section 3.2 and section 4 of our paper.

Maybe Orange U should be using Scheme.