#lang racket ;; Finds Racket sources in all subdirs (for ([path (in-directory)]) (when (regexp-match? #rx"[.]rkt$" path) (printf "source file: ~a\n" path)))
#lang web-server/insta ;; A "hello world" web server (define (start request) '(html (body "Hello World")))
#lang racket ; An echo server (define listener (tcp-listen 12345)) (let echo-server () (define-values (in out) (tcp-accept listener)) (thread (lambda () (copy-port in out) (close-output-port out))) (echo-server))
#lang racket ;; Report each unique line from stdin (let ([saw (make-hash)]) (for ([line (in-lines)]) (unless (hash-ref saw line #f) (displayln line)) (hash-set! saw line #t)))
#lang racket ; A picture (require 2htdp/image) (let sierpinski ([n 6]) (if (zero? n) (triangle 2 'solid 'red) (let ([next (sierpinski (- n 1))]) (above next (beside next next)))))
#lang racket/gui ; A GUI guessing game (define f (new frame% [label "Guess"])) (define n (random 5)) (send f show #t) (define ((check i) btn evt) (message-box "." (if (= i n) "Yes" "No"))) (for ([i (in-range 5)]) (make-object button% (format "~a" i) f (check i)))
#lang racket ; Simple web scraper (require net/url net/uri-codec) (define (let-me-google-that-for-you str) (let* ([g "http://www.google.com/search?q="] [u (string-append g (uri-encode str))] [rx #rx"(?<=<h3 class=\"r\">).*?(?=</h3>)"]) (regexp-match* rx (get-pure-port (string->url g)))))
#lang racket ;; A dice-rolling command-line utility (command-line #:args (dice sides) (for ([i (in-range (string->number dice))]) (displayln (+ 1 (random (string->number sides))))))
#lang racket ;; Print the Greek alphabet (for ([i (in-range 25)]) (displayln (integer->char (+ i (char->integer #\u3B1)))))
#lang htdp/bsl ; Any key inflates the balloon (require 2htdp/image) (require 2htdp/universe) (define (balloon b) (circle b "solid" "red")) (define (blow-up b k) (+ b 5)) (define (deflate b) (max (- b 1) 1)) (big-bang 50 (on-key blow-up) (on-tick deflate) (to-draw balloon 200 200))
#lang lazy ;; An infinite list: (define fibs (list* 1 1 (map + fibs (cdr fibs)))) ;; Print the 1000th Fibonacci number: (print (list-ref fibs 1000))
Draw more pictures or build a web server from scratch. Racket includes both batteries and a programming environment, so get started!
Grow your Program Racket's interactive mode encourages experimentation, and quick scripts easily compose into larger systems. Small scripts and large systems both benefit from native-code JIT compilation. When a system gets too big to keep in your head, you can add static types. | Grow your Language Extend Racket whenever you need to. Mold it to better suit your tasks without sacrificing interoperability with existing libraries and without having to modify the tool chain. When less is more, you can remove parts of a language or start over and build a new one. | Grow your Skills Whether you're just starting out, want to know more about programming language applications or models, looking to expand your horizons, or ready to dive into research, Racket can help you become a better programmer and system builder. |