This file contains 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 re | |
>>> msg1 = "aaabbbccc" | |
>>> msg2 = "dddbbbeee" | |
>>> re.findall("bbb(?=ccc)", msg1) # lookahead | |
['bbb'] | |
>>> re.findall("bbb(?=ccc)", msg2) | |
[] | |
>>> re.findall("bbb(?!ccc)", msg1) # negative lookahead | |
[] | |
>>> re.findall("bbb(?!ccc)", msg2) |
This file contains 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-account balance key) | |
(let ((try 0)) | |
(define (withdraw amount) | |
(if (>= balance amount) | |
(begin (set! balance (- balance amount)) | |
balance) | |
"Insufficient funds")) | |
(define (deposit amount) | |
(set! balance (+ balance amount)) | |
balance) |
This file contains 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-account balance key) | |
(define (withdraw amount) | |
(if (>= balance amount) | |
(begin (set! balance (- balance amount)) | |
balance) | |
"Insufficient funds")) | |
(define (deposit amount) | |
(set! balance (+ balance amount)) | |
balance) | |
(define (dispatch k m) |
This file contains 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-accumulator init) | |
(lambda (value) | |
(begin (set! init (+ init value)) | |
init))) |
This file contains 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
; No change, as same as before | |
(define (element-of-set? x set) | |
(cond ((null? set) false) | |
((equal? x (car set)) true) | |
(else (element-of-set? x (cdr set))))) | |
; Just use cons, don't need to use element-of-set anymore | |
(define (adjoin-set x set) | |
(cons x set)) |
This file contains 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 (element-of-set? x set) | |
(cond ((null? set) false) | |
((equal? x (car set)) true) | |
(else (element-of-set? x (cdr set))))) | |
(define (adjoin-set x set) | |
(if (element-of-set? x set) | |
set | |
(cons x set))) |
This file contains 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 (myequal? col1 col2) | |
(if (and (pair? col1) (pair? col2)) | |
(and (eq? (car col1) (car col2)) (myequal? (cdr col1) (cdr col2))) | |
(eq? col1 col2))) | |
(myequal? '(this is a list) '(this is a list)) ; #t | |
(myequal? '(this is a list) '(this (is a) list)) ; #f |
This file contains 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
(list 'a 'b 'c) ; '(a b c) | |
(list (list 'george)) ; '((george)) | |
(cdr '((x1 x2) (y1 y2))) ; '((y1 y2)) | |
(cadr '((x1 x2) (y1 y2))) ; '(y1 y2) | |
(pair? (car '(a short list))) ; #f | |
(memq 'red '((red shoes) (blue socks))) ; #f | |
(memq 'red '(red shoes blue socks)) ; '(red shoes blue socks) |
NewerOlder