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:

    Faultless honesty is a sine qua non of business life. Not alone the honesty according to the moral code and the Bible. When I speak of honesty I refer to the small, hidden, evasive meannesses of our natures. I speak of the honesty of ourselves to ourselves.
    Alice Foote MacDougall (1867–1945)

    No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.
    André Breton (1896–1966)