duplicates = multiple editions
A Classical Introduction to Modern Number Theory, Kenneth Ireland Michael Rosen
A Classical Introduction to Modern Number Theory, Kenneth Ireland Michael Rosen
This project has moved to https://github.com/jonhoo/drwmutex so it can be imported into Go applications.
Simplifying division of church-numbers with church-fractions.
A church number n
can be understood as the act of applying a function to a value n
times. That is:
(λ f x . (f (f (f x))))
Can be understood as the church number 3
, since it is an action that applies a function, f
, to a value, x
, 3 times. Here, I will be using "number" as a synonym for "church number" and, thus, a "natural number". Implementing addition, multiplication and exponentiation on church numbers is straightforward. Division is more awkward. Wikipedia, for instance, uses a recursive definition that doesn't have a normal form and is, thus, unsuited for strongly normalizing evaluators. This version is total, but has a huge normal form and works for integers, not naturals. There is a simpler way to define it, extending the same intuition to bu
#include "stdio.h" | |
#include "stdlib.h" | |
unsigned int max(unsigned int a, unsigned int b) { | |
return a > b ? a : b; | |
} | |
unsigned int bucket(unsigned int val) { | |
return val & 0xF0000000 >> 28; | |
} |
Basic unit type:
λ> replTy "()"
() :: ()
Basic functions:
# maybe.py - a Pythonic implementation of the Maybe monad | |
# Copyright (C) 2014. Senko Rasic <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# |
"""A simple implementation of a greedy transition-based parser. Released under BSD license.""" | |
from os import path | |
import os | |
import sys | |
from collections import defaultdict | |
import random | |
import time | |
import pickle | |
SHIFT = 0; RIGHT = 1; LEFT = 2; |
M[16],X=16,W,k;main(){T(system("stty cbreak") | |
);puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i | |
,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M | |
[w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<< | |
(l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k) | |
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d | |
-1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X] | |
*i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4; | |
)s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4|| | |
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2 |
# Simple Recommendation Engine in Ruby | |
# Visit: http://otobrglez.opalab.com | |
# Author: Oto Brglez <[email protected]> | |
class Book < Struct.new(:title) | |
def words | |
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort | |
end |
This post also appears on lisper.in.
Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.
Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):
The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.