版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/DanielDingshengli/article/details/82153310
1.生成可执行文件
DrRacket->Racket->Creat Executable…
2.λ符号通过Insert插入
3.Identifiers 标志符
( ) [ ] { } ” , ’ ` ; # | \ 除这几个字符以外都可以;
4.函数调用
#lang racket
(require racket/base)
(define(double x)
((if(string? x)string-append +) x x))
//(if(string? x)string-append +) evaluates to a function
> (1 2 3 4)
application: not a procedure;
expected a procedure that can be applied to arguments
given: 1
arguments...:
2
3
4
//Syntactically, the first expression in a function call could even be a number—but that leads to an error, since a number is not a function.
5.局部绑定
(define (converse s)
(define (starts? s2) ; local to converse
(define len2 (string-length s2)) ; local to starts?
(and (>= (string-length s) len2)
(equal? s2 (substring s 0 len2))))
(cond
[(starts? "hello") "hi!"]
[(starts? "goodbye") "bye!"]
[else "huh?"]))
> (converse "hello!")
"hi!"
> (converse "urp")
"huh?"
> starts? ; outside of converse, so...
starts?: undefined;
cannot reference an identifier before its definition
in module: top-level
internal name: starts?
编程:比较两个随机数的大小
(let ([x (random 4)]
[o (random 4)])
(cond
[(> x o) "X wins"]
[(> o x) "O wins"]
[else "cat's game"]))