Skip to content

Instantly share code, notes, and snippets.

@manuel
manuel / define-constructor.scm
Created February 22, 2012 15:40
Adventures in Hygienic Fexprs
;; 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)
@manuel
manuel / swap.lisp
Created March 10, 2012 01:26
Hygienic swap macro in EdgeLisp
(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))))
@manuel
manuel / conditions.txt
Created March 16, 2012 22:21
Integrating conditions and exceptions chat (german)
(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)))
@manuel
manuel / stack.virtua
Created March 18, 2012 23:55
Fexprs give you teh amazing stack traces
;; 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] ()
@manuel
manuel / callcc.scm
Created August 1, 2012 15:21
Call/CC in terms of Feeley's "Better API for First-Class Continuations"
(define (call/cc f)
(continuation-capture
(lambda (k)
(f (lambda (val)
(continuation-graft k (lambda () val)))))))
@manuel
manuel / dyn-wind-commentary.scm
Created August 11, 2012 12:45
Commenting on Oleg's dyn-wind.scm
;; 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
@manuel
manuel / representing-monads.scm
Created August 28, 2012 00:08
Error monad from Filinski's "Representing Monads"
;; Error monad from Filinski's "Representing Monads"
(define *default-prompt* (make-prompt))
(define (reflect m) (shift *default-prompt* k (ext k m)))
(define (reify t) (push-prompt *default-prompt* (unit (t))))
(define-record-type Success
(make-success a)
success?
(*
(define-class foo (make-foo))
(define-class bar (make-bar))
(define-generic (m obj))
(define-method (m (f foo)) 1)
(define-method (m (b bar)) 2)
(print (m (make-foo))) ; => 1
(print (m (make-bar))) ; => 2
(define-method (m (f foo)) 3)
(print (m (make-foo))) ; => 3
<html>
<head>
<title>Wat Sleeping Demo</title>
<script type="text/javascript" src="../../wat.js"></script>
</head>
<body>
<h1><a href="https://github.com/manuel/wat-js">Wat</a></h1>
<script type="text/javascript">
var code =
["begin",
@manuel
manuel / stuns
Created March 16, 2014 17:48 — forked from zziuni/stuns
# source : http://code.google.com/p/natvpn/source/browse/trunk/stun_server_list
# A list of available STUN server.
stun.l.google.com:19302
stun1.l.google.com:19302
stun2.l.google.com:19302
stun3.l.google.com:19302
stun4.l.google.com:19302
stun01.sipphone.com
stun.ekiga.net