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:

    Wise Draco comes, deep in the midnight roll
    Of black artillery; he comes, though late;
    In code corroborating Calvin’s creed
    And cynic tyrannies of honest kings;
    He comes, nor parlies; and the Town, redeemed,
    Gives thanks devout; nor, being thankful, heeds
    The grimy slur on the Republic’s faith implied,
    Which holds that Man is naturally good,
    And—more—is Nature’s Roman, never to be
    scourged.
    Herman Melville (1819–1891)

    In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.
    Michel de Montaigne (1533–1592)