Skip to content

Instantly share code, notes, and snippets.

View yamanetoshi's full-sized avatar

YAMANE Toshiaki yamanetoshi

View GitHub Profile
@yamanetoshi
yamanetoshi / app-controllers-conns_controller.rb
Created September 8, 2013 09:51
devise な Controller の雛形とその試験
class ConnsController < ApplicationController
before_filter :authenticate_user!
# GET /conns
# GET /conns.json
def index
@conns = current_user.conns
respond_to do |format|
format.html # index.html.erb
format.json { render json: @conns }
@yamanetoshi
yamanetoshi / stack.scm
Created November 10, 2013 07:32
EoPL Ex.2.15
(define empty-stack
(lambda ()
(lambda (sym)
(cond ((eqv? sym 'empty-stack?) #t)
(else
(eopl:error 'empty-stack "stack is empty ~s" sym))))))
(define push
(lambda (value stack)
(lambda (sym)
@yamanetoshi
yamanetoshi / gist:7409262
Created November 11, 2013 07:29
hex2signed function written in Gauche
(define bit-reversal
(lambda (str)
(let inner ((len (string-length str)) (instr str) (outstr ""))
(if (eq? 0 len)
outstr
(inner (- len 1)
(substring instr 1 (string-length instr))
(string-append outstr
(cond ((string=? (substring instr 0 1) "0") "1")
((string=? (substring instr 0 1) "1") "0"))))))))
@yamanetoshi
yamanetoshi / gist:7422189
Created November 11, 2013 23:02
EoPL Ex 2.16 test
(use gauche.test)
(add-load-path ".")
(load "env")
(test-start "list-find-last-position")
(test-section "list-find-last-position")
(test* "list-find-position"
1
(list-find-position 'a '(c a b a c a d e)))
@yamanetoshi
yamanetoshi / test-env.scm
Last active December 28, 2015 04:09
EoPL Ex.2.17 test
(use gauche.test)
(add-load-path ".")
(load "env")
(test-start "has-association?")
(test-section "empty-env")
(test* "empty-env"
#f
(has-association? (empty-env) 'a))
@yamanetoshi
yamanetoshi / env.scm
Created November 12, 2013 23:08
EoPL Ex.2.17
(define empty-env
(lambda ()
(lambda (sym search)
(if search
#f
(eopl:error 'apply-env "No binding for ~s" sym)))))
(define extend-env
(lambda (syms values env)
(lambda (sym search)
@yamanetoshi
yamanetoshi / test-env.scm
Created November 13, 2013 13:43
EoPL Ex 2.18 test
(use gauche.test)
(add-load-path ".")
(load "env")
(test-start "env")
(test-section "environment-to-list")
(test* "example"
'(extended-env-record (d x) (6 7)
(extended-env-record (y) (8)
@yamanetoshi
yamanetoshi / env.scm
Created November 13, 2013 13:44
EoPL Ex.2.18
(add-load-path "../../define-datatype")
(load "define-datatype")
(define-datatype environment environment?
(empty-env-record)
(extended-env-record
(syms (list-of symbol?))
(vals (list-of scheme-value?))
(env environment?)))
@yamanetoshi
yamanetoshi / stacks.scm
Created November 14, 2013 23:03
EoPL Ex.2.19
(add-load-path "../../define-datatype")
(load "define-datatype")
(define-datatype stack stack?
(empty-stack-record)
(extended-stack-record
(val scheme-value?)
(stk stack?)))
(define scheme-value?
@yamanetoshi
yamanetoshi / test-stacks.scm
Created November 14, 2013 23:05
EoPL Ex.2.19
(use gauche.test)
(add-load-path ".")
(load "stacks")
(test-start "stack")
(test-section "empty-stack")
(test* "empty-stack"
(test-error)
(stack-access 'pop (empty-stack)))