Random Art

Suppose we take an expression in x and y, built by nesting simple primitives: product, average, sin(pi*_), and cos(pi*_). These four operations map arguments in the range -1 to 1 to results in this same range. Thus, at any point with -1 <= x,y <= 1, our expression built from these primitives will return a value between -1 and 1. By scaling the answer to a grayscale value 0-255, we can plot the function in this 2-by-2 square. (From three such expressions, we can get red, green, and blue values for each point.)

What you get is some very nifty art!
(via PLT)
Addendum: 03/11/09
Noel posted some PLT Scheme code for implementation here:

#lang scheme/gui
(define (make-plotter drawing-fn size)
  (lambda (canvas dc)
    (for* ((x (in-range size))
           (y (in-range size)))
      (let* ([intensity (inexact->exact (round (* (/ (add1
                                                      (drawing-fn x y)) 2) 255)))]
             [colour (make-object color% intensity intensity intensity)])
        ;;(printf "~a ~a ~a\n" intensity x y)
        (send dc set-pen colour 1 'solid)
        (send dc draw-point x y)))))
(define (draw-grayscale size drawing-fn)
  (define frame (new frame%
                     [label "Random Art"]
                     [width size]
                     [height size]))
  (define canvas (new canvas%
                      [parent frame]
                      [paint-callback (make-plotter drawing-fn size)]))
  (send frame show #t))
(define (example1 x y)
  ;; some random stuff
  (sin (* (sin (* (cos x) y))
          (cos (*
                (sin (* (sin y) (cos x)))
                (cos (*  (cos (* y x)))))))))
(define (example2 x y)
  (if (> x 200)
      1
      -1))
;;(draw-grayscale 400 example1)

How PLTCOLLECTS works in PLT Scheme

R6RS Scheme systems are composed of code artifacts that are either libraries or top-level-programs. Libraries simply map to directories. In PLT Scheme, you can configure the library search path by configuring the PLTCOLLECTS environmental variable.
Having configured it and not getting results that I had expected, I asked about what I was doing wrong and got a great explanation here. It is pasted below.

The path-list function does something that is common with environment variables that specify paths: you have a string of several paths, separated by a “:”, which are searched in order. In addition, an empty path means “splice the default here”. So you get:
“/foo:/bar” — look in /foo and then in /bar
“/foo:/bar:” — look in /foo, then in /bar, and then in the default
“:/foo:/bar” — look in the default, then /foo then /bar
“/foo::/bar” — look in /foo then the default, then /bar
The last example shows why it’s useful — it allows you to both override PLT collections, as well as specify collections that could be overriden by PLT collections. For example, the first is useful if you want to try patching libraries, and the second is useful if you want to add a library that is added to a later version of PLT and you want to use it now but not when you upgrade.
Finally, on windows, the path separator character is “;” instead of a colon. (And remember the possible pitfalls with backslashes, or just use forward slashes.)

Hopefully that detail gets added to the documentation; it wasn’t obvious from reading it.

Tony Hoare sorry for inventing the null pointer

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn’t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. In recent years, a number of program analysers like PREfix and PREfast in Microsoft have been used to check references, and give warnings if there is a risk they may be non-null. More recent programming languages like Spec# have introduced declarations for non-null references. This is the solution, which I rejected in 1965.

(via Reddit)

How to render a ^ (carrot) in normal LaTeX text

Here are two ways to render a ^ (carrotcaret) in plain text within LaTeX:

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
A caret: \verb|^|
\end{document}
\textasciicircum

I tested them and both work as prescribed. They produce different carrotscarets.
(via comp.lang.texcomp.text.tex)
Addendum: 03/02/09
Corrected spelling of caret.
Addendum: 03/03/09
Wrote the wrong newsgroup name.

Minor Scheme

Minor Schemeis an implementation of the Scheme programming language. Its planned features include: good performance, via:

  • just-in-time and ahead-of-time compilers generating native machine code
  • precise, generational garbage collection
  • full support for native system threads
  • full source-level debugging
  • a C API and a foreign function interface, for interfacing with C code
  • a module system which supports separate compilation and cross-compilation
  • a hygenic macro system

Jim Blandy