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:
“Wise Draco comes, deep in the midnight roll
Of black artillery; he comes, though late;
In code corroborating Calvins 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 Republics faith implied,
Which holds that Man is naturally good,
Andmoreis Natures Roman, never to be
scourged.”
—Herman Melville (18191891)
“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 (15331592)