This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int mic = A0; | |
int THRESHOLD = 200; // sound must be > than to be considered on | |
// define the alarm patter ------------------------------------- | |
int ALARM_PATTERN_TIME[] = {30,40,30,40,30,120}; | |
int ALARM_PATTERN_STATE[] = {1,0,1,0,1,0}; | |
int ALARM_PATTERN_STATE_COUNT = 6; | |
int REPETITIONS = 1; | |
int GIVE = 25; // (time + give) | (time - give) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require r5rs) | |
(define (set-nth! n xs x) | |
(cond ((null? xs) (error "index out of bounds")) | |
((eq? n 0) (set-car! xs x)) | |
(#t (set-nth! (- n 1) (cdr xs) x)))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require r5rs) | |
(define xs '(1 2 3 4 5)) ;; xs is a list of numbers | |
xs | |
(set! xs "a list of numbers") ;; xs is now "a list of numbers" | |
xs | |
(define (update-1 arg) | |
(set! arg "this has only changed the value of 'arg' within 'update-1'") | |
arg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; delay and force are defined in r5rs, | |
;; but if we were defining them for ourselves | |
(define-syntax my-delay | |
(syntax-rules () | |
((_ expr) | |
(lambda () expr)))) | |
(define (my-force expr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> (define (foo) | |
(let ((xs '(1 2 3))) | |
(define (f) | |
(set! xs 0)) | |
(f) | |
xs)) | |
> (foo) | |
0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-counter-1) | |
(let ((counter 0)) | |
(lambda () | |
(set! counter (+ counter 1)) | |
counter))) | |
(define (make-counter-2) | |
(define counter 0) | |
(lambda () | |
(set! counter (+ counter 1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-balance) | |
(let ((balance 0)) | |
(define add-method | |
(lambda (value) (set! balance (+ balance value)))) | |
(define get-method | |
(lambda () balance)) | |
(define sub-method | |
(lambda (value) | |
(if (<= value balance) | |
(set! balance (- balance value)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
/** | |
* Created by boliver on 03/06/15. | |
*/ | |
public class Main { | |
public static void main(String args[]) { | |
Container value = new Container(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memoize(f): | |
computed = {} | |
def memoized(*args): | |
xs = computed.get(args) | |
if xs : | |
return xs | |
else : | |
value = f(*args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Memoize(object): | |
def __init__(self, f): | |
self.f = f | |
self.computed = {} | |
def __call__(self, *args): | |
xs = self.computed.get(args) | |
if xs : | |
return xs |