代码改变世界

scheme代码高亮

2013-10-11 15:17  allbymyself  阅读(317)  评论(0编辑  收藏  举报
(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!"