Skip to content

Instantly share code, notes, and snippets.

View kmicinski's full-sized avatar

Kristopher Micinski kmicinski

View GitHub Profile
@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))
#lang racket
;; Assignment 4: A church-compiler for Scheme, to Lambda-calculus
(provide church-compile
; provided conversions:
church->nat
church->bool
church->listof)
#lang racket
;; Midterm 2 -- Practice Solution
(foldr + 5 '(1 2 3))
;; call the lambda f
;; call the initial value i
(+ 1 (+ 2 (+ 3 5)))
#lang racket
;; How to handle let and let*
(let* ([x 1]
[y x])
((lambda (z) z) y))
(define (prim? s) (member s '(+ - * = equal? list cons car cdr null?)))
(define prim->op (hash '+ + '- - '* * '= = 'equal? equal? 'list list 'cons cons
'car car 'cdr cdr 'null? null?))
;; Closure-Creating Interpreters in Racket
#lang racket
;; expressions comprise the λ-calculus extended
;; to include numeric constants and the + builtin
(define (expr? e)
(match e
[(? number? n) #t]
[`(+ ,(? expr? e0) ,(? expr? e1)) #t]
[(? symbol? x) #t]
#lang racket
;; λ Calculus Exercises
;; Tue, Oct 25, 2022
;; CIS 352
;; Exercise 1:
;; ((λ (x) x) (λ (y) y))
;; Perform beta reduction on this term
;; For credit: the substitution must be made explicit
#lang racket
;; λ Calculus Exercises
;; Tue, Oct 25, 2022
;; CIS 352
;; Exercise 1:
;; ((λ (x) x) (λ (y) y))
;; Perform beta reduction on this term
;; For credit: the substitution must be made explicit
@kmicinski
kmicinski / 10-11.rkt
Created October 11, 2022 21:26
cis352 10/11/22
#lang racket
(provide (all-defined-out))
;;
;; CIS352 (Fall '22) -- IfArith Intro
;;
;; builtin functions
(define (function-name? fn)
(member fn '(+ - / * mod == =0? not)))