Uses a hash table to record previously seen lines. You can run this program in DrRacket, but it makes more sense from the command line.
To run the example, install Racket, start DrRacket, paste the example
program into the top area in DrRacket, and click the Run
button. Alternatively, save the program to a file and run racket
on
the file.
Form and function names in the code are hyperlinked to documentation, so click on them for more information.
#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))
Racket makes it easy to use TCP sockets and spawn threads to handle them. This program starts a server at TCP port 12345 that echos anything a client sends back to the client.
To run the example, install Racket, start DrRacket, paste the example
program into the top area in DrRacket, and click the Run
button. Alternatively, save the program to a file and run racket
on
the file.
Form and function names in the code are hyperlinked to documentation, so click on them for more information.
#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 ; 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))
Draw more pictures or build a web server from scratch. Racket includes both batteries and a programming environment, so get started!
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.
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.
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.