Code Examples
See also: Racket examplesHere'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:
Read more about this topic: Dr Racket
Famous quotes containing the words code and/or examples:
“Motion or change, and identity or rest, are the first and second secrets of nature: Motion and Rest. The whole code of her laws may be written on the thumbnail, or the signet of a ring.”
—Ralph Waldo Emerson (18031882)
“No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.”
—André Breton (18961966)