Skip to content

Instantly share code, notes, and snippets.

@jbclements
jbclements / master.rkt
Created April 10, 2019 22:25
our magnificent front end
#lang racket
;; this file uses the back-end
(require "back-end.rkt")
;; read lines from an input file
(define lines (file->lines "/tmp/input.src"))
(serialize (reverse lines))
@jbclements
jbclements / back-end.rkt
Created April 10, 2019 22:25
our magnificent rear end
#lang racket
;; this file implements the awesome back end of the compiler
(provide serialize)
;; given an intermediate representation, serialize it to a file
(define (serialize ir)
(call-with-output-file "/tmp/zz.txt"
@jbclements
jbclements / 2019-01-09.rkt
Created January 9, 2019 18:56
code from class, 2019-01-09
#lang typed/racket
(require typed/rackunit)
;; given a number, return the fizzbuzz game string
(define (fizzbuzz-num [n : Natural]) : String
(cond [(= 0 (modulo n 15)) "fizzbuzz"]
[(= 0 (modulo n 3)) "fizz"]
[(= 0 (modulo n 5)) "buzz"]
[else (number->string n)]))
@jbclements
jbclements / 2018-10-05-afternoon.rkt
Created October 5, 2018 22:04
afternoon code from friday
#lang typed/racket
(require typed/rackunit)
(define-type Value String)
(define-type ExprC (U ConcatC StrC))
(struct ConcatC ([l : ExprC] [r : ExprC])
#:transparent)
@jbclements
jbclements / 2018-10-03-afternoon.rkt
Created October 3, 2018 23:48
code from the afternoon class, 2018-10-03
#lang typed/racket
(require typed/rackunit)
(define-type Value String)
(define-type ExprC (U ConcatC StrC))
(struct ConcatC ([l : ExprC] [r : ExprC])
#:transparent)
@jbclements
jbclements / list-template.rkt
Created October 3, 2018 04:01
The list template, in Typed Racket.
#lang typed/racket
;; purpose statement goes here...
(define (fun-for-lists [l : (Listof Any)]) ; refine the types...
(match l
['() ...]
[(cons fst rst) ... fst ... (fun-for-lists rst) ...]))
@jbclements
jbclements / 2018-10-01-afternoon.rkt
Created October 1, 2018 23:10
lecture code from the afternoon class.
#lang typed/racket
(require typed/rackunit)
(: my-list (Listof Number))
(define my-list
(cons 6 (cons 12 (cons 13+4i (cons 16 '())))))
@jbclements
jbclements / 2018-10-01-morning.rkt
Created October 1, 2018 18:13
2018-10-01-morning.rkt
#lang typed/racket
(define my-list
(cons 3
(cons 4 (cons "horse" (cons (cons 16 '())
'())))))
;; determine the length of a list
(define (mylen [l : (Listof Any)]) : Natural
(match l
You will not, and will not permit anyone else to: (1) modify, adapt, alter,
translate or create derivative works of this Application; (2) use or merge
this Application, or any component or element of this Application, with
other software, databases or services not provided by us; (3) sublicense,
distribute, sell or otherwise transfer the Application to any other party;
(4) use the Application as a service bureau, or lease, rent or loan this
Application to any third party; (5) reverse engineer, decompile, disassemble
or otherwise attempt to derive the source code or structure of this
Application; (6) interfere in any manner with the operation of this
Application; (7) circumvent, or attempt to circumvent, any electronic
running example:
(((λ (f) (λ (y) (f y 9))) (λ (a b) (+ a b))) 3)
oh, let's write it in consieuten:
fun makeCaller ((int int -> int) f) (int -> int) {
fun caller(int y) int {
return f(y,9);
}