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:
“Many people will say to working mothers, in effect, I dont think you can have it all. The phrase for have it all is code for have your cake and eat it too. What these people really mean is that achievement in the workplace has always come at a priceusually a significant personal price; conversely, women who stayed home with their children were seen as having sacrificed a great deal of their own ambition for their families.”
—Anne C. Weisberg (20th century)
“It is hardly to be believed how spiritual reflections when mixed with a little physics can hold peoples attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.”
—G.C. (Georg Christoph)