This has grown into a repo itself, here is the latest version:
The syntax for patterns is
::= <var></var>
#!/usr/bin/wish | |
package require Tk | |
wm title . "numb" | |
grid [ttk::frame .c -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes | |
grid columnconfigure . 0 -weight 1 | |
grid rowconfigure . 0 -weight 1 |
(require-extension shift-reset) | |
;; http://www.diku.dk/~andrzej/papers/RM-abstract.html | |
(define list-monad | |
(list (lambda (x) | |
(list x)) | |
(lambda (m f) | |
(apply append (map f m))))) |
#lang racket | |
(require scheme/control) | |
;; Pattern matching | |
(define (pattern? p e) | |
(cond ((null? p) (null? e)) | |
((equal? p '_) #t) | |
((symbol? p) (and (symbol? e) (equal? p e))) |
http://homepage.ntlworld.com/edmund.grimley-evans/bcompiler.html | |
Bootstrapping a simple compiler from nothing | |
============================================ | |
This document describes how I implemented a tiny compiler for a toy | |
programming language somewhat reminiscent of C and Forth. The funny | |
bit is that I implemented the compiler in the language itself without |
module Bee where | |
import Fresh | |
import Control.Monad.Trans | |
import Control.Monad.Writer | |
import Data.Monoid | |
data Op | |
= Add | Sub | Mul | |
deriving (Eq, Show) |
type fresh = effect | |
operation gensym : unit -> int | |
end | |
let run s = handler | |
| val y -> (fun s -> y) | |
| s#gensym () k -> (fun s -> k s (s+1)) | |
| finally f -> f 0;; |
(* delimited continuations from Programming with Algebraic Effects and Handlers - Andrej Bauer, Matija Pretnar*) | |
type ('a, 'b) delimited = effect | |
operation shift : (('a -> 'b) -> 'b) -> 'a | |
end | |
let rec reset d = handler | |
| d#shift f k -> with reset d handle (f k) | |
swap : [256][8] -> [8] -> [8] -> [256][8] | |
swap s i j = [ s @ (if n == i then j else | |
if n == j then i else | |
n) | |
| n <- [0..255] | |
] | |
ksa_step : [inf][8] -> [8] -> [8] -> [256][8] -> ([8],[256][8]) | |
ksa_step key i j s = (j', swap s i j') | |
where j' = j + s@i + key@i |
This has grown into a repo itself, here is the latest version:
The syntax for patterns is
::= <var></var>
import Data.List | |
import Data.Ord | |
import Data.Bits | |
import Data.Char | |
data DInst | |
= Emit Char | |
| Backref Int Int | |
deriving (Eq, Show) |