Skip to content

Instantly share code, notes, and snippets.

@intellectronica
Created December 14, 2015 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intellectronica/5be93e566217d88dd093 to your computer and use it in GitHub Desktop.
Save intellectronica/5be93e566217d88dd093 to your computer and use it in GitHub Desktop.
#lang racket
(require compatibility/defmacro)
'(monkey . peanuts)
'(eenie . (meenie . (meiney . (moe . ()))))
'(eenie meenie meiney moe)
"I like peanut butter"
(string->list "I like peanut butter")
(map char->integer (string->list "I like peanut butter"))
'((monkey . animal)
(peanut . vegetable)
(africa . continent)
(sambal . condiment))
'(VP
(NP I)
(VP (VP like)
(NP (NP peanut)
(NP butter))))
(λ (x) x)
((λ (x) x) 42)
(define do-nothing (λ (x) x))
(do-nothing 42)
(* 2 5)
(define double (λ (x) ( * x 2)))
(double 5)
(let ((x 3)
(y 5))
(if (> (* x y) 20)
"x * y is greater than 20"
"x * y is not greater than 20"))
(define >20
(λ (x)
(> x 20)))
(let ((x 100)
(y 3))
(>20 (/ x y)))
(define >checker
(λ (compare-to)
(λ (x)
(> x compare-to))))
(define >50
(>checker 50))
(let ((x 100)
(y 3))
(>50 (/ x y)))
(defmacro unless (condition body)
(if (not condition)
body
''()))
(unless #f
"Didn't happen")
(defmacro repeat (times body)
(letrec ((rep (λ (times body)
(if (> times 0)
(cons body (rep (- times 1) body))
'()))))
(rep times body)))
(repeat 3
(display "Hello\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment