Skip to content

Instantly share code, notes, and snippets.

View kmicinski's full-sized avatar

Kristopher Micinski kmicinski

View GitHub Profile
#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)))
;; October 6, 2022
;; CIS352, Fall 2022
#lang racket
;; write the following in direct style
;; (i.e., perform recursive call, leave work
;; on the stack)
;; sum all elements in a list
(define (sum-list lst)
;; CIS352 -- Fall 2022
#lang racket
;; An S-expression or "structured" expression
;; is a list-like piece of data
(define x '(this is (an (s) expression)))
;; we define the tree? data type
;;
;; algebraic data types are called "algebraic" because they are
def take_first_n(lst, f, n):
ret_lst = []
for element in lst:
if (n == 0):
break
if (f(element)):
ret_lst.append(element)
n = n - 1
return ret_lst