This file contains 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 | |
;; Assignment 4: A church-compiler for Scheme, to Lambda-calculus | |
(provide church-compile | |
; provided conversions: | |
church->nat | |
church->bool | |
church->listof) |
This file contains 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 | |
;; Midterm 2 -- Practice Solution | |
(foldr + 5 '(1 2 3)) | |
;; call the lambda f | |
;; call the initial value i | |
(+ 1 (+ 2 (+ 3 5))) |
This file contains 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 | |
;; 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?)) |
This file contains 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
;; 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] |
This file contains 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 | |
;; λ 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 |
This file contains 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 | |
;; λ 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 |
This file contains 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 | |
(provide (all-defined-out)) | |
;; | |
;; CIS352 (Fall '22) -- IfArith Intro | |
;; | |
;; builtin functions | |
(define (function-name? fn) | |
(member fn '(+ - / * mod == =0? not))) |
This file contains 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
;; 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) |
This file contains 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
;; 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 |
This file contains 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
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 |