How to install and run racket scripts from CLI on OSX
$ brew install plt-racket
$ raco pkg install web-server
$ racket hello-server.rkt
$ brew install plt-racket
$ raco pkg install web-server
$ racket hello-server.rkt
Install racket:
brew cask install racket
Do NOT use brew install racket, because it will install the minimal-racket distribution which is missing a lot of tools and packages.
#lang racket
;;
;; From the command line:
;;
;; $ racket -it multiply.rkt
;;
;; Export multiply function so that we can call it from the REPL
;;
(provide multiply)
;;
;; Define the multiply method
;;
(define (multiply number n)
(* number n))
;;
;; Execute function
;;
(multiply 1 2)
(multiply 2 3)
;;
;; Write a unit test for the multiply method
;;
(module+ test
(require rackunit)
(check-equal? (multiply 0 0) 0)
(check-equal? (multiply 2 2) 4))
; HTTP example
(require net/http-client)
(http-sendrecv "google.com" "/" #:port 80)
; HTTPS example
(require net/http-client)
(http-sendrecv "google.com" "/" #:port 443 #:ssl? 'tls)