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
;; See http://okmij.org/ftp/continuations/implementations.html#dynamic-wind | |
;; and http://axisofeval.blogspot.com/2012/08/delimited-continuations-do-dynamic-wind.html | |
;; Slight trick here: use identity of yield-record-tag function as the actual tag | |
(define (yield-record-tag) yield-record-tag) | |
(define (make-yield-record v k) | |
(list yield-record-tag v k)) | |
;; Yield simply aborts up to the generator's caller, delivering to it | |
;; the yielded value and the continuation for resuming after the call |
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
(define (call/cc f) | |
(continuation-capture | |
(lambda (k) | |
(f (lambda (val) | |
(continuation-graft k (lambda () val))))))) |
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
;; Try pasting this into the Virtua REPL at http://manuel.github.com/virtua/ | |
;; (better use V8 - stack trace printing is quite slow atm) | |
(defun foo (a b c) (bar b)) | |
(defun bar (x) (quux x)) | |
(defun quux (x) (print-stack-trace (stack-frame))) | |
(foo 1 2 3) | |
#[Native-Combiner] () |
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
(10:56:17 PM) msimoni: also: ein lisp mit CS verwendet native exceptions ja für BLOCK/RETURN-FROM | |
(10:56:30 PM) Chris Neukirchen: ok | |
(10:56:48 PM) msimoni: ich habe (js-throw obj) === throw obj | |
(10:57:22 PM) msimoni: und ($js-try handler body-expr) === try { eval(body-expr) } catch(e) { apply(handler, e) } | |
(10:57:35 PM) msimoni: das sind die primitives in der VM | |
(10:57:51 PM) msimoni: darauf baue ich BLOCK/RETURN-FROM so: | |
(10:58:06 PM) msimoni: | |
(def Block-Escape (make-class ())) | |
(def make-block-escape (lambda () (make-instance Block-Escape))) |
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
(defmacro swap (a b) | |
#`(let ((tmp ,b)) | |
(setq ,b ,a) | |
(setq ,a tmp))) | |
(let ((x 1) (tmp 2)) | |
(swap x tmp) | |
(assert (and (= x 2) (= tmp 1))) | |
(swap tmp x) | |
(assert (and (= x 1) (= tmp 2)))) |
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
;; As part of the implementation of Virtua's [1] object system I need | |
;; a facility called DEFINE-CONSTRUCTOR that defines a convenient | |
;; function for creating an instance of a class and setting its slots. | |
(define-constructor make-person Person (firstname lastname)) | |
;; should be operationally equivalent to | |
(define make-person | |
(lambda (firstname lastname) |
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
Welcome to Racket v5.1.1. | |
> (define-syntax bar (syntax-rules () ((_) 1))) | |
> (define (foo) (bar)) | |
> (foo) | |
1 | |
> (define-syntax bar (syntax-rules () ((_) 55555))) | |
> (foo) | |
1 ;; NOOOOOOOOOO!!! |
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
(run-cc | |
($lambda () | |
($let ((p (make-prompt))) | |
(+ 2 ($push-prompt p | |
($if (with-sub-cont p | |
($lambda (k) | |
(+ ($push-sub-cont k #f) | |
($push-sub-cont k #t)))) | |
3 | |
4)))))) |
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
;;; Sample of EdgeLisp's content-based storage system | |
;;; https://github.com/manuel/edgelisp/blob/master/client/base.lisp | |
;; Create a blob containing the file's contents. | |
(defvar test-blob (base-make-blob "Hello content-centric world!")) | |
#[base-blob Hello content-centric world!] | |
;; Create a tree with a directory entry named "hello.txt" pointing to the blob's ID (hash). | |
(defvar test-tree | |
(base-make-tree (list (base-make-dentry "hello.txt" (base-object-id test-blob))))) |
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
abstract class Term<T> { | |
abstract T eval(); | |
} | |
class IntegerTerm extends Term<Integer> { | |
Integer value; | |
IntegerTerm(Integer value) { this.value = value; } | |
Integer eval() { return value; } | |
} |