Skip to content

Instantly share code, notes, and snippets.

Avatar

Kristopher Micinski kmicinski

View GitHub Profile
View gist:b6931fafe4f3b4d814984a8bf82e4ef9
.decl R(x:number,y:number)
.decl H(x:number)
.decl G(x:number)
.decl P(x:number,y:number)
.output R
R(x,y) :- H(x), G(y), P(x,y).
H(1).
H(2).
@kmicinski
kmicinski / basic.dl
Created Aug 27, 2020
CIS 700 Notes: 8/27/20
View basic.dl
.decl Edge(x:number,y:number)
.output Edge
// Facts
Edge(0,1).
Edge(1,2).
Edge(1,3).
Edge(3,0).
// Rule
View build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
def sootClassesJar = file('lib/sootclasses-2.5.0.jar')
dependencies {
compile files(sootClassesJar)
View graph-to-dot.rkt
;; Render a graph in dot format. Graph is a hash from nodes to sets of
;; nodes. Terminal nodes need not be included in the domain of graph.
(define (graph->dot graph)
(define nodes (foldl (lambda (k s) (set-add (set-union (hash-ref graph k) s) k)) (set) (hash-keys graph)))
(define nodesl (set->list nodes))
(define node->num
(foldl (lambda (i h) (hash-set h (list-ref nodesl i) i)) (hash) (range (length nodesl))))
(displayln "digraph sloggraph {")
(for ([i (range (length nodesl))])
(displayln (format "\tn~a [label=\"~a\"];" i (string-replace
View hash.rkt
;; Hash a vector of numbers (all interpreted to be unsigned 64-bit
;; values) based on the first `len` entries in u64-vector. This uses
;; the same hash function as the backend's tuple_hash.
(define (tuple-hash u64-vector prefix-len)
(define base 14695981039346656037)
(define prime 1099511628211)
(define resulting-hash
(foldl
(lambda (i cur-hash)
(let* ([chunk (vector-ref u64-vector i)]
View a5.rkt
;; From video lecture: stack-passing interpreters and continuation-passing style (CPS)
;; CEK. Stack-passing style interpreters
#lang racket
(require racket/trace)
(define my* (lambda (x y) (* x y)))
;; Direct-style implementation of the factorial function, n!
(define (factorial n)
View bigstepinterp.rkt
#lang racket
;; Assignment 3: A CE (Control and Environment) interpreter for Scheme
(provide interp-ce)
(define (lambda-num? e)
(match e
[(? number? n) #t]
[(? symbol? x) #t]
View codingexam0-practice.rkt
#lang racket
; takes two lists and builds a list of pairs of each element
; return empty list for unused elements as in '(0 1) '(2 3 4)
; (zip '(0 1) '(2 3)) --> '((0 . 2) (1 . 3))
(define (zip lst0 lst1)
(match (cons lst0 lst1)
[(cons `(,hd0 . ,tl0) `(,hd1 . ,tl1)) (cons (cons hd0 hd1) (zip tl0 tl1))]
[(cons '() '()) '()]
[(cons _ _) '()]))
View freevars.rkt
(define (term? t)
(match t
[(? symbol? x) #t]
[`(lambda (,(? symbol? x)) ,(? term? e-body)) #t]
[`(,(? term? e0) ,(? term? e1)) #t]
[_ #f]))
(define (freevars t)
(match t
[(? symbol? x) (set x)]
View lambda-0.rkt
;; lambda calculus notes
#lang racket
;; Lambda calculus terms in Racket:
;; 'x
;; '(lambda (x) x)
;; '((lambda (x) x) x), '((lambda (x) x) y)
;; '((lambda (x) x) (lambda (y) y))
You can’t perform that action at this time.