Skip to content

Instantly share code, notes, and snippets.

;; use apply
(apply + (iota 10 1))
;; use fold
(fold (lambda (n r)
(+ n r))
0
(iota 10 1))
;; recursive recursion
(define insert-g
(lambda (set-f)
(lambda (new old lat)
(fold-right (lambda (e l)
(cond ((eq? old e)(set-f new old l))
(else (cons e l))))
'()
lat))))
;; member?
(define member?
(lambda (a lat)
(cond ((null? lat) #f)
((eq? a (car lat)) #t)
(else (member? a (cdr lat))))))
(define member?
(lambda (a lat)
テスト
@valvallow
valvallow / fold,unfold,pair-fold,reduce.scm
Created February 11, 2010 03:33
fold, reduce, fold-pair, unfold
;; Gauche ユーザリファレンス: 10.2 srfi-1 - List library http://practical-scheme.net/gauche/man/gauche-refj_102.html#SEC310
;; Making The Road Wiki - Programming::Scheme::SRFI1 http://ow.ly/13jo0
;; fold
(fold +
0
'(1 2 3 4 5))
; -> 15
@valvallow
valvallow / TheSeasonedSchemer.scm
Created February 11, 2010 07:38
The Seasoned Schemer, sum-of-prefixes
;; sum-of-prefixes
; (2 1 9 17 0) -> (2 3 12 29 29)
; (1 1 1 1 1) -> (1 2 3 4 5)
; letrec
(define sum-of-prefixes
(lambda (tup)
@valvallow
valvallow / TheSeasonedSchemer.scm
Created February 11, 2010 14:26
fold, fold-right,
; fold, fold-right
(fold (lambda (x y z)
(display (format "x = ~a, y = ~a, z = ~a\n" x y z))
(+ x y z)) 0 '(1 1 1) '(1 1 1))
;; x = 1, y = 1, z = 0
;; x = 1, y = 1, z = 2
;; x = 1, y = 1, z = 4
;; 6
(fold (lambda (m n o r)
@valvallow
valvallow / TheSeasonedSchemer.scm
Created February 11, 2010 14:43
The Seasoned Schemer, scramble
;; scramble
; (1 1 1 3 4 2 1 1 9 2) -> (1 1 1 1 1 4 1 1 1 9)
; (1 2 3 4 5 6 7 8 9) -> (1 1 1 1 1 1 1 1 1)
; (1 2 3 1 2 3 4 1 8 2 10) -> (1 1 1 1 1 1 1 1 2 8 2)
(define one?
(lambda (n)
(= n 1)))
(((lambda (f)
(lambda (n)
(if (zero? n)
1
(* n ((f f)(- n 1))))))
(lambda (f)
(lambda (n)
(if (zero? n)
1
(* n ((f f)(- n 1))))))) 5)
@valvallow
valvallow / hello.js
Created February 17, 2010 19:15
test
/*
(function (){
alert('hello');
})();
*/
var hello = function () { alert('hello')};