我正在学习Jason Hickey 的 Objective Caml 简介。只是有一个关于表达的问题。
所以它说:
Definitions using let can also be nested using the in form.
let identifier = expression1 in expression2
The expression expression2 is called the body of the let. The variable named identifier
is defined as the value of expression1 within the body. The identifier is defined only in
the body expression2 and not expression1.
A let with a body is an expression; the value of a let expression is the value of
the body.
let x = 1 in
let y = 2 in
x + y;;
let z =
let x = 1 in
let y = 2 in
x + y;;
val z : int = 3
好的。我对上述说法不太了解。
第一的
The variable named identifier
is defined as the value of expression1 within the body. The identifier is defined only in
the body expression2 and not expression1.
这是什么意思?identifier
也是如此the value of expression1
,但只是在体内expression2
?这是否意味着identifier
仅在 中有效expression2
但具有 的值expression1
?那么定义是否identifier
有意义,因为它只存在于expression2
?
第二
让我们看看这个例子:
let x = 1 in
let y = 2 in
x + y;;
所以我不明白这个let
声明的意义。x = 1
当然,给身体的意义let y=2 in x+y;;
何在?
第三
让 z = 让 x = 1 在让 y = 2 在 x + y 中;;
那么如何理清这句话的逻辑呢?
如果采用这种定义形式:let identifier = expression1 in expression2
expression1
上面的let
陈述是什么?是let x = 1
吗?
谁能告诉我nesting let
某种Java
方式的逻辑?或更容易理解的方式?