scheme - 在 Racket 中写负数

标签 scheme racket

2 – (-12/x) = -4

让我困惑的是负数 12。我应该把负号放在哪里?

(define (math x)
( = ( - ( / 12 x) 2) 4))

最佳答案

负号是数字本身的一部分,您可以像使用任何其他语言一样编写它:

(define (math x)
( = ( - ( / -12 x) 2) 4))

输出:

> (math 2)  ; 2-(-12/2) = -4 -> 2-(-6) = -4 -> 2 + 6 = -4 -> 8 = -4 (FALSE)
#f
> (math -2) ; 2-(-12/-2) = -4 -> 2-(6) = -4 -> -4 = -4 (TRUE)
#t

关于scheme - 在 Racket 中写负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14451042/

相关文章:

inheritance - 可扩展的宏定义

与 + 和 append 一起使用的树折叠定义

scheme - Scheme Meta Circular Evaluator 中的模式匹配功能

user-interface - Racket /GUI : responding to double-click and hover events

image - 如何更改 Racket 中的图像大小

scheme - 在Scheme中使用cons、list、append

Scheme 函数从 x 上下写数字

functional-programming - 我可以在 PLTScheme 中反汇编我的代码吗?

scheme - HtDW 与 HtDP 有何关联?

scheme - 将两个包含 3 个字符的列表组合成 3 对