Created
January 29, 2026 20:59
-
-
Save kmicinski/e293a8f9ce386da8a91ba7a9fd847f27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lang racket | |
| ;; CIS 352 -- Spring 2026 | |
| ;; 1/27/26 (I believe) | |
| ;; quickanswer.harp-lab.com | |
| ;; the define form lets us define funcitons | |
| ;; (define (f x y z) e-body) | |
| (define (both-even? n0 n1) | |
| 'todo) | |
| (define (f x) | |
| (if (< x 0) | |
| (* x x) | |
| (* x x x))) | |
| ;; the simplest list is | |
| '() | |
| '(x y z) | |
| ;; How do I set up conditional statements correctly? | |
| ;; Function returns true when l is equal to '() | |
| ;; and returns false otherwise | |
| (define (is-the-empty-list? l) | |
| (equal? l '())) | |
| (define (f+ x) | |
| (if (equal? x 0) | |
| 5 | |
| (if (equal? x 5) | |
| 6 | |
| (+ x 2)))) | |
| (define (f++ x) | |
| (cond [(equal? x 0) 5] | |
| [(equal? x 5) 6] | |
| [else (+ x 2)])) | |
| ;; Recursion | |
| ;; def sum_list(l): | |
| ;; i = 0 | |
| ;; acc = 0 | |
| ;; while (i < len(l)): | |
| ;; acc = acc + l[i] | |
| ;; i = i + 1 | |
| ;; return acc | |
| (define (sum-list l) | |
| (define (h i acc) | |
| (if (< i (length l)) | |
| (h (+ i 1) (+ acc (list-ref l i))) | |
| acc)) | |
| (h 0 0)) | |
| ;; get the ith element from the list l | |
| ;; preconditions: | |
| ;; - l is not empty | |
| ;; - i < (length l) ∧ l >= 0 | |
| (define (list-ref l i) | |
| (if (equal? i 0) | |
| (first l) | |
| (list-ref (rest l) (- i 1)))) | |
| (define (sum-list+ l) | |
| (if (empty? l) | |
| 0 | |
| (+ (first l) (sum-list+ (rest l))))) | |
| (define (recursive-funtcion l ...) | |
| (if (empty? l) | |
| 'base-case | |
| ;; call (recursive-function (rest l)) and combine it | |
| ;; with (first-l) | |
| 'recursive-case)) | |
| ;; if l is '() then return #f | |
| ;; if l is a (cons x y), return (even (first l)) | |
| (define (is-first-list-element-even? l) | |
| (if (equal? '() l) | |
| #f | |
| (even? (first l)))) | |
| ;; car is first | |
| ;; cdr is rest | |
| ;; return all elements in l that satisfy the predicate f | |
| (define (filter f l) | |
| (if (empty? l) | |
| '() | |
| (if (f (first l)) | |
| (cons (first l) (filter f (rest l))) | |
| (filter f (rest l))))) | |
| ;; return the elements of l that are even? | |
| (define (filter-evens l) | |
| (filter even? l)) | |
| ;; return the sub-list of l whose elements are < 2 | |
| (define (filter-lt2 l) | |
| ;; a lambda says: "I am a function, without a name, defined | |
| ;; exactly here. I take the argument x, and I return my body expression | |
| #;(filter (lambda (x) (< x 2) l) l) | |
| 'todo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment