Skip to content

Instantly share code, notes, and snippets.

@kmicinski
Created January 13, 2026 21:45
Show Gist options
  • Select an option

  • Save kmicinski/369d966d1fc1d1b7f35e1f1d699ac48e to your computer and use it in GitHub Desktop.

Select an option

Save kmicinski/369d966d1fc1d1b7f35e1f1d699ac48e to your computer and use it in GitHub Desktop.
;; CIS352 notes -- 01/13
#lang racket
;; I can use define to define both values, and also functions
;; this is a value
(define foo 42)
;; Racket is expression-based, meaning that functions evaluate
;; their body expressions, and the result of evaluating any expression
;; is the computation's whole result...
(define (identity x) x)
;; To call a function, I write:
;; (f arg0 ...) <-- f is the name, arg0 and etc. are the arguments
(identity 20)
(define (bar x y)
(+ (* x x) (* 2 y)))
(define (fac x)
(if (equal? x 0) ;; don't use =, equal? is a check for structural equality
1
(* x (fac (- x 1)))))
;; How can we see that if isn't a function
;; Call-by-value: to evaluate a function, first evaluate its arguments, then
;; use those arguments to evaluate the body.
;; (f arg0 arg1 ...) -- each of arg0 arg1 etc.... have to be evaluated before f's body
;; may be evaluated. This is a fact in CBV languages. It's part of something called
;; "evaluation strategy." Sometimes it's also called an "eager" evaluation strategy
(define (loop) (loop))
(define (if-v e-g e-t e-f) (if e-g e-t e-f))
(if-v (equal? 2 2) "2 is equal? to 2" (loop))
(if (equal? 2 2) "2 is equal? to 2" (loop))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment