Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
@fetburner
fetburner / bsearch.v
Created April 27, 2016 12:02
binary search
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

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

CommonLisp:

hash-table

Scheme:

hash-table (SRFI-69), hashtable (R6RS Scheme)

Haskell:

Map

OCaml:

@gakuzzzz
gakuzzzz / 1_.md
Last active August 2, 2023 01:59
Scala の省略ルール早覚え

Scala の省略ルール早覚え

このルールさえ押さえておけば、読んでいるコードが省略記法を使っていてもほぼ読めるようになります。

メソッド定義

def concatAsString(a: Int, b: Int): String = {
  val a_ = a.toString();
  val b_ = b.toString();
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active April 29, 2024 09:09
Reader Macros in Common Lisp

Reader Macros in Common Lisp

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.

@tsdeng
tsdeng / emacs_scala.md
Last active June 26, 2018 16:43
Configure Emacs for Scala

Basic Support

  1. Install ctags-exuberant
  2. Install gnu global
    • brew install global --with-exuberant-ctags
    • add following line in bash export GTAGSCONF=/usr/local/share/gtags/gtags.conf
    • edit gtags.conf, in the exuberant-ctags section, add following line :langmap=Scala:.scala:\
@omasanori
omasanori / gist:8023683
Last active December 31, 2015 17:59
R'0'RSを読む

R'0'RSを読む

これは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と呼びます。

@KOBA789
KOBA789 / parser.js
Created August 28, 2013 03:35
実際動かない(struct リテラルくらいしかパースできない)
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");
@kazuho
kazuho / gist:6052876
Created July 22, 2013 10:26
JavaScript の yield で非同期なコードを動機っぽく書く例
// 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);