Skip to content

Instantly share code, notes, and snippets.

View kmicinski's full-sized avatar

Kristopher Micinski kmicinski

View GitHub Profile
#lang racket
;; CIS352 -- Fall 2023
;; Lambdas
;; first order function -- no functions as arguments
;; O(n^2) the way it's written -- an easier implementation
;; is not easy functionally, need a different representation
(define (reverse lst)
(if (empty? lst)
#lang racket
;; Recursion over lists
(cons 1 (cons 2 (cons 3 (cons 4 '()))))
;; more laboriously as ...
(let ([last-link (cons 4 '())])
(let ([second-to-last-link (cons 3 last-link)])
(let ([third-to-last-link (cons 2 second-to-last-link)])
(cons 1 third-to-last-link))))
-- see cek.slog
def var := String
-- terms
inductive term : Type where
| Ref : var → term
| Lam : var → term → term
| App : term → term → term
open term
#lang racket
;; CIS352 -- Spring 2023, 4/4 and 4/6/2023
;; Beginning to the Church encoding project
;; output
(define (lambda-calculus? e)
(match e
[(? symbol? x) #t]
[`(lambda (,(? symbol? x)) ,(? lambda-calculus? e-body)) #t]
#lang racket
;; CIS352 -- Spring 2023, 4/4/2023
;; Beginning to the Church encoding project
;; output
(define (lambda-calculus? e)
(match e
[(? symbol? x) #t]
[`(lambda (,(? symbol? x)) ,(? lambda-calculus? e-body)) #t]
;; CIS352 -- 2/28/23
#lang racket
(define x
(hash "A" (set "B" "C")
"B" (set "C" "A")
"C" (set "B")))
(define (count-edges graph)
(foldl
#lang racket
;; Interpreters, Feb 23
(define (arith-expr? e)
(match e
[(? number? n) #t]
[`(,(? number? n0) + ,(? number? n1)) #t]
[`(,(? number? n0) - ,(? number? n1)) #t]
[`(,(? number? n0) * ,(? number? n1)) #t]
@kmicinski
kmicinski / 02-21.rkt
Created February 21, 2023 17:21
folds
#lang racket
;; tail recursive functions
(define (filter f l)
(define (h l acc)
(match l
['() acc]
[`(,hd . ,tl)
(if (f hd)
(h tl (cons hd acc))
#lang racket
(define x '(this (is an) s expression))
;; Write a function that takes an input list l
;; and adds 2 to every element of the list
;; assume all elements are numbers
#;(define (add-two-to-each l)
(define addtwo (lambda (x) (+ x 2)))
;(define (addtwo x) (+ x 2))
#lang racket
;; Thursday, Dec 8, 2022
;; Class 2 -- Type Inference
;;
;; In this exercise, we will study type inference, and
;; a variety of type system features.
(provide (all-defined-out))