- CommonLisp:
hash-table
- Scheme:
hash-table (SRFI-69), hashtable (R6RS Scheme)
- Haskell:
Map
OCaml:
Require Import Arith Div2 Omega Recdef. | |
Function bsearch (p : nat -> bool) n { wf lt n } := | |
match n with | |
| O => 0 | |
| _ => | |
let m := div2 n in | |
if p m then bsearch p m | |
else S m + bsearch (fun x => p (S m + x)) (n - S m) | |
end. |
:- use_module(library(socket)). | |
write_atom(Stream,Atom) :- | |
atom_codes(Atom,Codes), | |
write_codes(Stream,Codes). | |
write_codes(_,[]) :- !. | |
write_codes(Stream,[Code|Tail]) :- | |
put_code(Stream,Code), | |
write_codes(Stream,Tail). |
(* | |
OCaml translation of the ideas explained in http://fumieval.hatenablog.com/entry/2014/09/22/144401 | |
To emulate the higher kinded polymorphism, the technique used explained in https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf | |
*) | |
module StateMonad = struct | |
type ('s, 'a) m = 's -> 's * 'a |
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.
これはLisp Advent Calendar 2013の19日目の文章です。
表題に出てくるR'0'RSは正式な名称ではありません。表題で私がR'0'RSと呼んでいる文章はSchemeの言語仕様を記述した報告書、いわゆるRnRSの元祖といえる"Scheme: An Interpreter for Extended Lambda Calculus"です。この文章はAI Memo 349としても知られています。以下ではAIM 349と呼びます。
var util = require('util'); | |
function Nothing () {} | |
Object.Nothing = Nothing; | |
Array.prototype.maybeMap = function (callback, thisArg) { | |
var T, A, k; | |
if (this == null) { | |
throw new TypeError(" this is null or not defined"); |
// based on http://labs.cybozu.co.jp/blog/kazuho/archives/2007/05/coopthread.php | |
function get_all(urls) { | |
runnable(function (next) { | |
for (var i = 0; i < urls.length; i++) { | |
// build request | |
var xhr = new XMLHttpRequest(); | |
xhr.open("get", urls[i], true); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState == 4) | |
next(xhr.responseText); |