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
Walter Bright's MEM Package | |
--------------------------- | |
PREFACE: | |
-------- | |
The files, MEM.H and MEM.C which constitute the MEM package were originally | |
published in the March-April 1990 edition of Micro Cornucopia magazine, now | |
sadly out of print. The files as they appear in SNIPPETS have been edited |
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
#!/usr/bin/env python2 | |
from pisi.api import * | |
from pisi.util import human_readable_size | |
from os.path import basename as b | |
from sys import argv | |
ctx = set() |
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
import functools | |
c = lambda f: lambda g: lambda x: f (g (x)) | |
add = lambda x: lambda y: x + y | |
const = lambda x: lambda y: x | |
uncurry = lambda f: lambda x, y: f (x) (y) | |
succ = add (1) | |
fold = lambda f: lambda z: lambda xs: functools.reduce(uncurry(f), xs, z) | |
len = fold (c (const) (succ)) (0) |
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
#> shell doesn't have multiline comments | |
: <<comment | |
ok | |
buddy | |
here's | |
your | |
multiline | |
comment |
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
{-# language OverloadedStrings #-} | |
import Prelude hiding (getLine, putStr, filter, length, take, drop) | |
import Data.ByteString | |
import Data.Maybe | |
main = do | |
ln <- getLine | |
putStr $ f ln -- putStr and getLine from ByteString |
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
let rec perm = function | |
| [] -> [] | |
| [x] -> [[x]] | |
| xs -> | |
let rec aux i ls = | |
let (l,r) = splitat i ls in | |
match r with | |
| [] -> [] | |
| h::r_ -> | |
let rest = l @ r_ in |
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
-- possibly the worst implementation out there but | |
combinations [] = [] | |
combinations xs = go (length xs) (map pure xs) xs where | |
go 1 zs __ = zs | |
go n zs ys = [ y:z | y <- ys, z <- go (n-1) zs ys ] |
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 show(fmt, ...) (printf("%s: ", #__VA_ARGS__), printf(fmt, __VA_ARGS__)) | |
#define show8(x) printf(#x":\t%02hhx (%hhd)\n", x, x) |
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
{-# OPTIONS_FRONTEND -Wno-overlapping #-} | |
import AllSolutions | |
insert :: a -> [a] -> [a] -- warning: overlapping patterns = ndet | |
insert x xs = x : xs | |
insert x (y:ys) = y : insert x ys | |
perm :: [a] -> [a] | |
perm [] = [] |
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
(* | |
nat(z). | |
nat(s(N)) :- nat(N). | |
plus(N, z, N). | |
plus(N, s(M), s(A)) :- plus(N, M, A). | |
mult(_, z, z). | |
mult(N, s(M), B) :- mult(N, M, A), plus(N, A, B). |
OlderNewer