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 | |
| ;; tail recursive functions | |
| (define (filter f l) | |
| (define (h l acc) | |
| (match l | |
| ['() acc] | |
| [`(,hd . ,tl) | |
| (if (f hd) | |
| (h tl (cons hd acc)) |
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 | |
| (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)) |
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 | |
| ;; 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)) |
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 | |
| ;; Assignment 4: A church-compiler for Scheme, to Lambda-calculus | |
| (provide church-compile | |
| ; provided conversions: | |
| church->nat | |
| church->bool | |
| church->listof) |
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 | |
| ;; 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 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 | |
| ;; 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 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
| ;; 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 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 | |
| ;; λ 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 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 | |
| ;; λ 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 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 | |
| (provide (all-defined-out)) | |
| ;; | |
| ;; CIS352 (Fall '22) -- IfArith Intro | |
| ;; | |
| ;; builtin functions | |
| (define (function-name? fn) | |
| (member fn '(+ - / * mod == =0? not))) |