2014-05-08

Racket v6.0.1

Racket version 6.0.1 is now available from

http://racket-lang.org/

  • A new racket/undefined library exports undefined as the value currently produced by
    (letrec ([x x]) x)
    This library anticipates a future where that expression will raise an exception. The racket/undefined library will continue to offer the undefined value as a bridge between versions and as a last resort.
  • The drawing and GUI libraries provide improved support for high-resolution bitmaps and their use on Retina displays. For example, read-bitmap includes a #:try-@2x? option to trigger substitutions through the usual "@2x" naming convention.
  • Check Syntax cooperates with Typed Racket to show arrows and other Check Syntax highlighting even when there is a type error.
  • Functions provided via contract-out that have first-order contracts perform better.
  • The contract boundary between typed/untyped modules is much less expensive. Typed Racket now avoids generating contracts for places where contracts failures cannot happen.
  • Occurrence typing now works better with when/unless. Example:
    (let ((x (read)))
      (unless (number? x) (error 'bad-input))
      (add1 x))
  • Types in Typed Racket are now pretty-printed.
  • Function types can now be written in prefix style, which is now preferred and is used for printing. Infix function types are still accepted for backwards compatibility.
  • A new ->* type constructor is used for writing types for functions with optional and keyword arguments. The notation is similar to the matching contract combinator.
  • Typed Racket forms do not have a : suffix by default now. For example, the struct form replaces struct:. The suffixed versions are all provided for backwards compatibility.
  • Typed Racket now has preliminary support for classes and objects. However, it is still experimental and the APIs are subject to change.
  • Type aliases in Typed Racket now support recursion and mutual recursion. For example, (define-type (MyList X) (U Null (Pair X (MyList X)))) is now a valid type alias.
  • Plot correctly renders intersecting 3D graphs and non-grid-aligned 3D rectangles.
  • Elements in plots output in PDF/PS format have the same relative scale as in other formats. In particular, it is not necessary to adjust plot-font-size to make PDF plots look the same as PNG.

2014-04-24

Registration for (fourth RacketCon)

Registration for (fourth RacketCon) is now open. Tickets are 30$.

https://www.eventbrite.com/e/racketcon-2014-tickets-11408046775

(fourth RacketCon) will be held on September 20th, and will be co-located with Strange Loop in St. Louis.

RacketCon is a yearly event where members of the Racket community get together, featuring talks and demos about the things you do with Racket.

To get you excited, here's a sneak peek at the roster of speakers so far:

  • Michael Fogus (keynote)
  • Matthew Butterick
  • Matthew Flatt
  • Jay McCarthy
  • Daniel Prager
  • Neil Toronto
We still have room for more speakers. If you've built something cool with Racket, we want to hear about it! Hope to see you there! Vincent, for the Racket team

2014-03-12

The new Racket home page

Racket now has a new look for its web presence. You can see it at http://racket-lang.org (modulo DNS propagation).

The new pages improve on the old in several ways:

  • More information is now on the front page.
  • The site works much better small devices, such as phones.
  • It's easier to find important parts of the site, like the package directory.
  • The download process is more streamlined -- now it's only 2 clicks.

We also wanted to have a new look, and a description that talks about why Racket is exciting.

Finally, we've taken this opportunity to shift our web hosting entirely to Amazon S3, for which Greg Hendershott's aws package has been very helpful.

While the new pages have been under development for quite a while, we're still happy to take bug reports, suggestions and (especially) patches: all of the site can be found here:
  https://github.com/plt/racket/tree/master/pkgs/plt-services/meta/new-web
with the framework for building the site here:
  https://github.com/plt/racket/tree/master/pkgs/plt-web-pkgs

The site is built using Eli's scribble/html library, which is very nice to use.

I'd especially like to thank Eli and Matthew for their help with this -- going from my hacked-up HTML prototype to the smooth-building and well-organized code we have now has taken lots of work.

Sam

2014-02-26

Racket v6.0

Racket version 6.0 is now available from

http://racket-lang.org/

Racket 6.0 has a new package system, including a catalog of hundreds of already-available packages. Please visit

http://pkgs.racket-lang.org/

for an overview of the packages.

Racket versions 5.3.4 through 5.3.6 included "beta" versions of the package system. Racket version 6.0 incorporates many improvements suggested by preliminary experiences in those versions:

  • A package is treated as a single collection by default, so it is even easier to use a GitHub repository as a package. Get started quickly: http://docs.racket-lang.org/pkg/getting-started.html
  • DrRacket includes a new package manager GUI, available via the    File|Package Manager ... menu item. The GUI is also available as a stand-alone program via the "gui-pkg-manager" package.
  • The main Racket distribution has been separated into about 200 packages. The Racket installer combines the core system with bundled versions of these packages.
    Alternatively, you may now install a Minimal Racket distribution — which is about 1/10 the size of the main distribution — and add only those packages that you need.
  • Package installation supports pre-built packages that include compiled byte code and rendered documentation, meaning packages can be installed quickly when built versions are available. All packages in the main distribution are available in pre-built form.

The recent 5.92 and 5.93 releases served as release candidates for 6.0, and 6.0 includes a few additional repairs related to the package system.

Further improvements to the package system are in the works, notably including package documentation on the package-catalog web site.

COMPATIBILITY NOTE: PLaneT, the previous Racket package system, will remain in place for the foreseeable future, but we expect all package work to shift to the new system.

Beyond the package system, this release brings a number of other changes:
  • Racket's HTML documentation has a new and improved look, thanks to Matthew Butterick.
  • The documentation includes a style guide, "How to Program Racket".
  • Racket's JIT compiler supports the ARM architecture.
  • Racket supports the Mac's Retina display mode.
  • The performance of the Typed Racket compiler improved by 50% on some typed programs; e.g., see http://bit.ly/1d0Ye4z
  • The profiler provides a new mode that uses the errortrace library to produce fine-grained profiles.
  • A new contract profiler reports how much time programs spend checking contracts, and which contracts are most expensive.
  • The math/flonum library exports fast 105-bit precision operations.
  • Check Syntax handles generated identifiers, especially those introduced by struct (e.g. field selectors) and Redex (e.g., e_1, e_2)
  • 2htdp/batch-io includes functions for dealing with html/xml in files and web sites as X-expressions plus conveniences for web-based graph traversals.
  • The `gen:set' generic interface extends set operations to work on user-defined types that implement set methods, as well as on other set-like built-in types, such as lists.
  • Picts support conversion to SVG format.
  • Under unix, Racket provides desktop entries (.desktop files) for its graphical executables.

2013-12-17

Typed Racket and Classes

Recently we had our inaugural Racket Salon meetup here in Boston, graciously organized by Dan King. At the meetup I gave a short demo about the upcoming support for classes and object-oriented programming in Typed Racket. In this blog post, I’ll go over the concepts I presented in my demo.

Background

As many readers already know, Typed Racket is a gradually-typed sister language to Racket. That means it’s a statically-typed language that accommodates the idioms of Racket. Programs written in Racket should seamlessly port to Typed Racket with the addition of type annotations here and there. You can even keep some parts of the program dynamically-typed and Typed Racket will make sure those parts won’t break the type invariants via contracts.

Of course, supporting all Racket idioms is quite a lot of work, especially since it’s a constantly evolving language. One of the big pieces missing from Typed Racket right now is support for classes and objects. Since the GUI library heavily uses the class system, it’s important to support the object-oriented subset of Racket.

Supporting classes isn’t trivial though. There are a bunch of issues, but the main ones are: (1) the class system is built as a complex macro and so reconstructing the information needed to type-check is tricky, and (2) we need to make sure that interoperation between Racket and Typed Racket using classes/objects can be done safely.

I won’t go over the technical details about the implementation in this blog post, but contact me if you’re interested. In the rest of the blog post, I’ll show some examples to demonstrate what programming in Typed Racket with classes looks like. Just so you know, these examples won’t work in the current version of Typed Racket but will be supported in a future release.
Side note: If you like to live dangerously, you can track the experimental branch with support for classes here.

Fishes and types

To start out, let’s look at an untyped example from the Racket Guide on classes and objects. The following snippet defines a fish% class. The class has several features: an initialization argument named size, a private field named current-size, three methods get-size, grow, and eat.
(define fish%
  (class object%
    (init size)
    (define current-size size)
    (super-new)
    (define/public (get-size)
      current-size)
    (define/public (grow amt)
      (set! current-size (+ amt current-size)))
    (define/public (eat other-fish)
      (grow (send other-fish get-size)))))
The notation should seem mostly familiar if you’ve programmed in Java or other object-oriented languages. The % suffix is a convention for identifiers that are bound to class values. The object% value is the superclass of fish% and is the root class of all class hierarchies. The initialization argument size is used when constructing an instance of a class:
> (new fish% [size 3])
(object:fish% ...)
Note that in Racket, classes are just values that can be passed around like anything else. For example, you can even do silly things like define nested inheriting classes:
> (new (class (class object% (super-new) (displayln "superclass"))
         (super-new)
         (displayln "subclass")))
superclass
subclass
(object:eval:4:0 ...)
In practice, this feature is quite useful since it lets you define mixins easily. That’s a topic for another blog post.

Side note: In other words, Racket has first-class classes. This is a term you might see used in the programming language literature.

Adding types to the fish program is easy. First, we can introduce a type definition for the fish class.
(define-type Fish%
  (Class (init [size Real])
         [get-size (-> Real)]
         [grow (Real -> Void)]
         [draw (-> Pict)]
         [eat ((Instance Fish%) -> Void)]))

This type definition says that Fish% is a class type with the given initialization argument and methods types. Note that the type of the fish class Fish% is not the same as the type of its instances (Instance Fish%). This is an important distinction to make, since both the fish class value and fish object values may appear in the same program.

Side note: If you’re familiar with Typed Racket, you may be surprised that the recursive reference to Fish% in the type definition works. Future versions of Typed Racket will support implicit recursive type definitions.

With the type definition in hand, we can just annotate the class value with the type:
(: fish% : Fish%)
(define fish%
  (class object%
    (init size)
    (: current-size Real)
    (define current-size size)
    (super-new)
    (define/public (get-size)
      current-size)
    (define/public (grow amt)
      (set! current-size (+ amt current-size)))
    (define/public (eat other-fish)
      (grow (send other-fish get-size)))))
We do need an extra type annotation on the private field because its type isn’t included in the type definition above. This fish definition is a bit boring, so let’s spice it up a bit by making fishes drawable:
(define-type Fish%
  (Class (init [size Real])
         (get-size (-> Real))
         [grow (Real -> Void)]
         ; a type for the new method
         [draw (-> Pict)]
         [eat ((Instance Fish%) -> Void)]))
(: fish% : Fish%)
(define fish%
  (class object%
    (init size)
    (: current-size Real)
    (define current-size size)
    (super-new)
    (define/public (get-size)
      current-size)
    ; new draw method
    (define/public (draw)
      (standard-fish (* current-size 10)
                     (* current-size 5)))
    (define/public (grow amt)
      (set! current-size (+ amt current-size)))
    (define/public (eat other-fish)
      (grow (send other-fish get-size)))))
The new draw method that’s been added to the fish relies on some functions from the pict library. Since that’s not currently included in Typed Racket’s standard libraries, we need to give its exports some types:
; this would go at the top of the file before fish%
(require/typed pict
               [#:opaque Pict pict?]
               [standard-fish (Real Real [#:color String] -> Pict)])
The #:opaque import form in Typed Racket lets you create a new type that corresponds to some predicate, in this case pict?. It’s useful for bringing in datatypes from dynamically-typed Racket libraries. With that new type, we can give a type for the standard-fish function.

In the end, you can interact with some fish and draw them:
> (define dory (new fish% [size 5]))
> dory
- : (Instance Fish%)
(object:fish% ...)
> (send dory draw)
- : Pict
image
> (send dory eat dory)
> (send dory draw)
- : Pict
image

Conclusion

At Racket Salon, I talked about a few other things including mixins and converting a slightly larger program that uses the GUI library. They didn’t translate well to a blog setting so I didn’t include them here. Racket Salon was a fun event, so I encourage anyone in the Boston area to attend!

Typed Racket’s support for classes will land in a future version of Racket, possibly the release after v6.0.

2013-08-10

Racket v5.3.6

Racket version 5.3.6 is now available from

http://racket-lang.org/

Racket v5.3.6 is a bug-fix release. It eliminates errors from v5.3.5 that people have found over the summer.

2013-07-31

RacketCon 2013 Signup

RacketCon sign up is now open! http://bit.ly/racketconsignup2013

RacketCon will be held at Northeastern University in Boston on September 29. The details of the event can be found on the website: http://con.racket-lang.org

We also have a page on Lanyrd for the event: http://lanyrd.com/2013/racketcon/

More information about the schedule will be posted in the upcoming weeks.