Interactive Image Generation with Racket

Not sure whether I blogged about this or not already, but I sure could not find it so here goes.

A while back my buddy Bruce needed some randomly generated images in a particular format for a project. The specs were more of a “I’ll know it when I see it” kind of thing so I volunteered to help out and have some fun with Racket in the process.

The nifty part is that during development and also use you may preview the images directly inside of DrRacket. This feature made the work so, so fun (other editors do this, too).

Here is a copy of the code. Try running manual.scm and the image will show up in the REPL. If you run automatic.scm it will dump the image in /tmp.

Scribfile: File and Operating System related Scribble Functionality

Is a little library that provides two forms, one to read a lispy language file into a codeblock and another that makes a system call and renders the results in a verbatim form. Pretty helpful for demos of non-Racket code and who knows what else.

Thanks Racket team, and Danny and Matthew for getting this working.

This is How Easy it is to Make Changes to DrRacket

DrRacket is open-source (LGPL) editor for Racket. Sometimes you want to make changes to it. For example today I wanted to enable online compilation on single-core machines. Here is how easy it is to do it:

  1. Assuming that DrRacket is already installed. This is a normal installation using the installer; you do not typically have to check out the Git repo to make changes.
  2. Asked Robby how to make the change. Robby is super everybody knows that, he explained the fix. The check for enabling the feature is in module-language.rkt. Here are the steps
  3. cd /opt/racket/5.3.1/collects/drracket/private/
    sudo cp module-language.rkt module-language.rkt-ORG
    # Made the change
    # View it
    diff module-language.rkt module-language.rkt-ORG 
    <                    ;;(> (processor-count) 1))
    <                    (> (processor-count) 0))
    >                    (> (processor-count) 1))
    <                    ;;(> (processor-count) 1))
    <                    (> (processor-count) 0))
    >                    (> (processor-count) 1))
    # Tell Racket to recompile that collection (aka library)
    sudo raco setup -l drracket
    # Restart DrRacket
  4. Now the online compilation indicator shows up and errors are automatically flagged.
  5. It works fine on a 1.6GHz Pentium with 2GB of RAM.

Hope this gave you a taste of how easily and quickly you can try new stuff out in DrRacket itself.

Here is how it looks with it turned on:

DrRacket for the Truly Impatient V02

DrRacket is a wonderful editor. It is so feature rich that the first time you begin using it, you may end up missing out on how powerful and pleasant it is to use due to the multitude of options and features. The following is my attempt to share the most useful and interesting features and get a new-user up and running and feeling really good about it as quickly as possible.
Continue reading “DrRacket for the Truly Impatient V02”