Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
@nyuichi
nyuichi / gist:3436159
Created August 23, 2012 12:19
jsx cat
import "js.jsx";
import "../lib/js/nodejs.jsx";
native class Buffer {
function constructor(size : int);
}
native __fake__ class FS {
function write(fd : variant, buffer : Buffer, offset : int, length : int, position : Nullable.<int>) : void;
@nyuichi
nyuichi / monads.scm
Created August 24, 2012 03:04
Monadic Operators in Scheme
;;; Monadic Operators
;;; List Monad
(define (mappend fn . lists)
(apply append (apply map fn lists)))
(define (bind monad . funcs)
(fold mappend monad funcs))
(define unit list)
@nyuichi
nyuichi / ralist.cpp
Created August 26, 2012 18:18
Purely Functional Random Access List
#include <stddef.h>
#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
template<typename T>
class Tree {
template<typename U> friend class RandomAccessList;
@nyuichi
nyuichi / pvec.scm
Created August 28, 2012 17:20
Clojure's Persistent Vector on Gauche
(define-class <pvector> ()
((size :init-keyword :size)
(shift :init-keyword :shift)
(root :init-keyword :root)))
(define pv:null (make <pvector> :size 0 :shift 0 :root #()))
(define (update-vector vec i val)
@nyuichi
nyuichi / idea.txt
Created August 29, 2012 18:14
easy way to use side-effect on clojure
;; want to add mutable variables
;; but how to treat with closures that have free mutable variables?
;; a traditional way: using actors
;; calling a function equals sending a message to the function, which can be said
;; an actor in this meaning.
(let ((a 1))
Music : コネクト
Rank : C
Score : 126619
Max Combo : 88
Complete : 22
Solve : 121
Miss : 172
Minus Score : -5162
Corrected Character : 772/1065
Corrected Percent : 72%
@nyuichi
nyuichi / vlist.scm
Created September 1, 2012 09:37
VList on Gauche
(define-class <vlist> ()
((base :init-keyword :base :accessor base-of)
(offset :init-keyword :offset :accessor offset-of)
(size :init-keyword :size :accessor size-of)
(block :init-keyword :block :accessor block-of)))
(define (make-vlist base offset size block)
(make <vlist> :base base :offset offset :size size :block block))
(define vlist-null (make-vlist () 0 -1 #()))
@nyuichi
nyuichi / hoge.cpp
Created September 7, 2012 08:59
C++の代入のまぎらわしいアレ
int main()
{
// int a(1); という意味だと解釈されてaのコンストラクタが呼ばれる。
int a = 1;
// int b(); b = 1; という意味だと解釈されてbのコンストラクタが呼ばれたあと、bの代入演算子b.operator=(1);が呼ばれる。
int b;
b = 1;
}
@nyuichi
nyuichi / dee-binding.lisp
Created September 24, 2012 04:42
deep binding vs shallow binding
;;;; **deep binding**
;;; look up
(cdr (assq 'the-symbol *the-stack*))
;;; funcall
; wind...
(loop for arg in args
@nyuichi
nyuichi / hoge.jsx
Created September 27, 2012 09:56
bug?
class Klass {
function method(x : int) : int {
if (x == 0) { // compiler complains that x is not initialized
return 1;
}
else {
var x = 2;
return x;
}
}