ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Section2 Number, Expression, Simple Programs

Section2 Number, Expression, Simple Programs

翻译 Linux操作系统 作者:wq_brilliant 时间:2016-06-13 22:30:58 0 删除 编辑

《How to Design Programs》这本书要讨论的是如何设计程序,首先在preface 就抛出了design recipe,并在以后的章节里慢慢扩展。                        

The Design Recipe for Functions
Problem Analysis & Data Definition
Contract, Purpose & Effect Statement, Header
Examples
Function Template
Function Definition  
Tests

全书编程语言Scheme。

Section2 -> http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-5.html

本章备忘:

简单的加减乘除

(+ 5 5)     (- 5 5)     (* 3 4)      (/ 8 12)    


再来个四则运算         

(* (+ 2 2) (/ (* (+ 3 5) (/ 30 10)) 2))


优点:不需要考虑计算顺序,只要碰到长这个样子                 
(operation A ... B)
并且A B是数字,都可以直接计算


不仅仅支持上面的运算,还支持复杂的,比如下面这些
    

(sqrt A) computes (A)1/2
(expt A B) computes AB
(remainder A B) computes the remainder of the integer division A/B
(log A) computes the natural logarithm of A

(sin A) computes the sine of A radians


注意:Scheme 提供精确的计算,比如说 (/ 44 14) 计算结果是 22/7,(sqrt 2)
= #i1.4142135623731。给自己提个醒,以后处理无理数要小心。

数字计算结束,下面讲函数。

定义函数:             
(define (func_name  param1 param2 ...)
   把运算放这里   )

调用函数:
(func_name  param1 param2 ...)

===========================================================
这一章简单介绍了一些运算,如何定义函数,并且在DrScheme里执行这些运算和调用这些函数。
完毕。              

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29000138/viewspace-2119765/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 单引号和双引号
请登录后发表评论 登录
全部评论

注册时间:2014-12-27

  • 博文量
    6
  • 访问量
    3338