Skip to content

Instantly share code, notes, and snippets.

View leque's full-sized avatar

OOHASHI Daichi leque

View GitHub Profile
@leque
leque / gist:7729596
Created December 1, 2013 07:40
aif with implicit renaming macros
(define-syntax aif
(ir-macro-transformer
(lambda (form inject cmp)
(let ((it (inject 'it))
(expr (car (cdr form)))
(then (car (cdr (cdr form))))
(else (car (cdr (cdr (cdr form))))))
`(let ((,it ,expr))
(if ,it ,then ,else))))))
@leque
leque / gist:8035729
Last active December 31, 2015 19:49

各言語のコレクション操作高階関数(メソッド、手続き)

Language
Common Lisp mapc mapcar find-if remove-if-not reduce reduce :from-end t some every
Scheme for-each map find filter fold, fold-left fold-right any, exists every, for-all
Haskell mapM_ map find filter foldl foldr any all
Caml Light do_list map - - it_list list_it exists for_all
OCaml iter map find filter, find_all fold_left fold_right exists for_all
F# iter map find filter fold foldBack exists forall
@leque
leque / sc-cut.scm
Last active August 29, 2015 13:56
(define-syntax %cut
(sc-macro-transformer
(lambda (form use-env)
(capture-syntactic-environment
(lambda (mac-env)
(let ((rargs (cadr form))
(rbody (caddr form))
(rest (cdddr form)))
(define (id=? x y)
(and (identifier? x)
(define-syntax cut
(sc-macro-transformer
(lambda (form use-env)
`(cut% () () ,@(cdr form)))))
(define-syntax cut%
(sc-macro-transformer
(lambda (form env)
(let ((slots (cadr form))
(define-syntax sc-cut
(sc-macro-transformer
(lambda (form use-env)
(capture-syntactic-environment
(lambda (mac-env)
(define (id=? x y)
(and (identifier? x)
(identifier=? use-env x
mac-env y)))
(let loop ((rargs '())
@leque
leque / coq-8.4pl3-elisp.diff
Last active August 29, 2015 13:57
Coq Extaction to Emacs Lisp / Common Lisp
diff --git a/plugins/extraction/scheme.ml b/plugins/extraction/scheme.ml
index 7915bc8..ee2b3fb 100644
--- a/plugins/extraction/scheme.ml
+++ b/plugins/extraction/scheme.ml
@@ -23,14 +23,15 @@ open Common
let keywords =
List.fold_right (fun s -> Idset.add (id_of_string s))
[ "define"; "let"; "lambda"; "lambdas"; "match";
- "apply"; "car"; "cdr";
+ "apply"; "car"; "cdr"; "list"; "letrec";
% -*- mode: prolog -*-
% type inference rules in
% Danvy, O., and A. Filinski: "A Functional Abstraction of Typed Contexts",
% Technical Report 89/12, DIKU, University of Copenhagen (July 1989).
extend_env(Env, Var, Typ, [Var:Typ|Env]).
lookup_env([Var:Typ|_], Var, Typ).
lookup_env([_|Env], Var, Typ) :- lookup_env(Env, Var, Typ).
ty(_, X, A, A, int) :- integer(X).

各言語での Map, Dictionary 的なものの名前

CommonLisp:
hash-table
Scheme:
hash-table (SRFI-69), hashtable (R6RS Scheme)
Haskell:
Map

OCaml:

// Haskell-style Functor in Java
// See also:
// highj: http://code.google.com/p/highj/
// Higher-kinded programming in OCaml: https://github.com/ocamllabs/higher
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
/**
* type application F[A]
(* https://issues.scala-lang.org/browse/SI-5195 *)
let swap (a, b) = (b, a)
type (_, _) f =
MapF : ('a -> 'b) -> ('a, 'b) f
| Pipe : ('a, 'b) f * ('b, 'c) f -> ('a, 'c) f
| Flip : ('a * 'b, 'b * 'a) f
let pipe = function
| MapF f, Flip -> MapF (fun x -> swap (f x))