racket

  1. let 和 let* 区别
// 这是对的
(let* ([x (random 4)]
       [o (random 4)]
       [diff (number->string (abs (- x o)))])
  (cond [(> x o) (string-append "X wins by " diff)]
        [(> o x) (string-append "O wins by " diff)]
        [else "cat's game"])
    )

// 这是错的
(let ([x (random 4)]
       [o (random 4)]
       [diff (number->string (abs (- x o)))])
  (cond [(> x o) (string-append "X wins by " diff)]
        [(> o x) (string-append "O wins by " diff)]
        [else "cat's game"])
    )

lets 变量定义后可以直接使用 let 不可以.

转载于:https://www.cnblogs.com/daihanlong/p/6257822.html

你可能感兴趣的:(racket)