(defun iedit-symbol-in-defun () "Enter `iedit-mode' to rename the symbol in current function, or exit it." (interactive) (if iedit-mode (progn (iedit-mode -1) (widen)) (progn (if (thing-at-point 'symbol) (progn (narrow-to-defun) (iedit-mode t) (message "When done, run `epy-iedit-in-defun' again to quit.") ) (error "You need to put cursor on identifier.") ))))
(define-struct parent (childs name date eyes)) ;;youngest (define Gustav (make-parent empty 'Gustav 1988 'blue)) (define Fred*Eva (list Gustav)) ;;younger (define Adam (make-parent empty 'Adam 1950 'yellow)) (define Dave (make-parent empty 'Dav 1955 'black)) (define Eva (make-parent Fred-Eva 'Eva 1965 'blue)) (define Fred (make-parent Fred-Eva 'Fred 1966 'pink)) (define Carl*Bettina (list Adam Dave Eva)) ;;older (define Carl(make-parent Carl*Bettina 'Carl 1926 'green)) (define Bettina(make-parent Carl*Bettina 'Bettina 1926 'green)) ;是否有後代是藍眼睛 (define (blue-eyed-descendant? a-parent) (cond [(symbol=? (parent-eyes a-parent) 'blue) true] [else (blue-eyed-children? (parent-childs a-parent))])) (define (blue-eyed-children? list-of-childs) (cond [(empty? list-of-childs) false] [(symbol=? (parent-eyes (first list-of-childs)) 'blue) true] [else (blue-eyed-children?(rest list-of-childs))])) ;;搜索後代中誰是藍睛眼 ;;blue-eyed-desendant-who? a-parent->symbol (define (blue-eyed-desendant-who? a-parent) (append (cond [(symbol=? (parent-eyes a-parent) 'blue) (list (parent-name a-parent))] [else empty]) ;先搜索本身,藍眼睛爲真,返回本身,不然返回empty (blue-eyed-children-who? (parent-childs a-parent))));再繼續搜索子代 ;相併集append ;;搜索子代中誰是藍眼睛 (define (blue-eyed-children-who? list-of-childs) (cond [(empty? list-of-childs) empty] ;若是子代是空集爲真,則返回empty,遞歸結束 [else (append (list (blue-eyed-desendant-who? (first list-of-childs))) (blue-eyed-children-who? (rest list-of-childs)))])) ;反之有子代,則搜索第一個的藍眼睛後代和剩餘的藍眼睛子代(包含求第一個的藍眼晴後代和剩餘的藍眼睛子代(...)) (define (appendx lst) (cond [(empty? lst) empty] [(empty? (first lst)) (appendx (rest lst))] [else (append (first lst) (appendx (rest lst)))]) ) (define (atom? x) (not (or (cons? x) (null? x)))) (define lst-out empty) (define (fun lst) (cond [(empty? lst) empty] [(atom? (first lst)) (cond [(atom? (rest lst)) ] (append (list (first lst)) lst-out)] [else (append (fun (first lst)) (fun (rest lst)))]))
# include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; } int main() { std::cout << "Hello, world!" << std::endl; return 0; } int main() { std::cout << "Hello, world!" << std::endl; return 0; } int main() { std::cout << "Hello, world!" << std::endl; return 0; } int main() { std::cout << "Hello, world!" << std::endl; return 0; }
# include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; }
(format t "Hello world") 函數定義: (defun hello-world () (format t ("hello, world!")) 調用函數: (hello-world) ;;"hello,world!"