Skip to content

Instantly share code, notes, and snippets.

View samth's full-sized avatar

Sam Tobin-Hochstadt samth

View GitHub Profile
; lower-bound = alpha
; upper-bound = beta
(define (maximum-value-with-cutoff s depth lower-bound upper-bound)
(let-values
([(maximum-value new-lower-bound within-upper-bound?)
(for*/fold
([maximum-so-far -inf.0]
[new-lower-bound lower-bound])
([successor (successors s)]
[successor-value (in-value (value-with-cutoff successor
@samth
samth / gist:1652932
Created January 21, 2012 14:28 — forked from jlongster/gist:1651726
Macros
;; AST style:
((equal? term "cond")
(define (transform i)
(if (or (> i node.children.length)
(eq? i node.children.length))
null
(let ((n (vector-ref node.children i)))
(let ((condition (vector-ref n.children 0))
(res (ast.node ast.LIST
(defn analysis->map
"Convert Java Object expr into nested maps"
; result type:
; (rec X (U {:op :def
; :env {:source Object
; :line Object}
; :var Var}
; {:op :if
; :env {:source Object
; :line Object}
@samth
samth / fp.dot
Created May 2, 2012 15:01 — forked from fogus/fp.dot
early influence graph of fp languages -- this is not meant to be a complete time line. I'm mostly concerned with the root and inner nodes.
digraph G {
KRC -> Miranda;
ML -> Miranda;
KRC -> SASL;
SASL -> Miranda;
Miranda -> Haskell;
Hope -> Haskell;
Hope -> ML;
Clean -> Haskell;
FP -> Haskell;
@samth
samth / clj_port.rkt
Created May 17, 2012 14:27 — forked from frenchy64/clj_port.rkt
clojure.core/isa? port to Typed Racket
;(defn isa?
; "Returns true if (= child parent), or child is directly or indirectly derived from
; parent, either via a Java type inheritance relationship or a
; relationship established via derive. h must be a hierarchy obtained
; from make-hierarchy, if not supplied defaults to the global
; hierarchy"
; {:added "1.0"}
; ([child parent] (isa? global-hierarchy child parent))
; ([h child parent]
; (or (= child parent)
#lang racket
(module m typed/racket
;; the generated contract for this is
;;
;; (define-values:102 (generated-contract4:103)
;; (#%app:104
;; continuation-mark-key/c/proc:105
;; (#%app:106 flat-named-contract 'Integer exact-integer?)))
;;
module Post {
import Comment from Comment;
import Model from DS;
export get Post() { return _Post; }
class _Post extends Model {}
_Post.schema((post) => {
post.attr('title');
@samth
samth / try2.js
Created November 18, 2012 19:07 — forked from wycats/gist:4106771
module Post {
import Comment from Comment;
import Model from DS;
class Post extends Model {}
Post.schema((post) => {
post.attr('title');
post.attr('body');
post.hasMany('comments', (args...) => Comment(args...));
@samth
samth / test
Created December 3, 2012 22:21 — forked from takikawa/test
. Type Checker: untyped identifier apply-contract imported from module <private/base.rkt> in: #%module-begin
. Type Checker: untyped identifier coerce-contract imported from module <private/guts.rkt> in: #%module-begin
. Type Checker: untyped identifier flat-named-contract imported from module <racket/contract> in: #%module-begin
. Type Checker: untyped identifier build-source-location imported from module <syntax/srcloc> in: #%module-begin
. Type Checker: Summary: 4 errors encountered in:
#%module-begin
#%module-begin
#%module-begin
#%module-begin