Dr Racket - Code Examples

Code Examples

See also: Racket examples

Here's a trivial "hello world" program:

#lang racket "Hello, World!"

Running this program produces the output:

"Hello, World!"

Here's a slightly less trivial program:

#lang racket (require 2htdp/image) (let sierpinski (if (zero? n) (triangle 2 'solid 'red) (let (freeze (above t (beside t t))))))

This program, taken from the Racket website, draws a Sierpinski triangle, nested to depth 8.

Using the #lang directive, a source file can be written in different dialects of Racket. Here is an example of the factorial program in Typed Racket, a statically typed dialect of Racket:

#lang typed/racket (: fact (Integer -> Integer)) (define (fact n) (cond ))

Read more about this topic:  Dr Racket

Famous quotes containing the words code and/or examples:

    ...I had grown up in a world that was dominated by immature age. Not by vigorous immaturity, but by immaturity that was old and tired and prudent, that loved ritual and rubric, and was utterly wanting in curiosity about the new and the strange. Its era has passed away, and the world it made has crumbled around us. Its finest creation, a code of manners, has been ridiculed and discarded.
    Ellen Glasgow (1873–1945)

    It is hardly to be believed how spiritual reflections when mixed with a little physics can hold people’s attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.
    —G.C. (Georg Christoph)