scip习题(1) scheme和c实现的对比
习题1.3
定义一个过程,它以三个数为参数,返回其中较大的两个数的平方和.
(Define a procedure thats three numbers as argument and return the sum of the square of two large number.)
scheme实现
(define (square x)
(* x x))
(define (sum_of_square x y)
(+ (square x)
(square y)))
(define (bigger x y)
(if (> x y)
x
y))
(define (smaller x y)
(if (< x y)
x
y))
(define (sum_square x y z)
(sum_of_square (bigger x y)
(bigger (smaller x y) z)))
c语言实现
//用C语言实现scip(计算机程序构造与解释)的一些习题。对比并进一步了解scheme的函数式思想
//Define a procedure thats three numbers as argument and return the sum of the square of two large
//numbers.
//C language implementation #include "stdafx.h"
#include<iostream>
using namespace std; int square(int x);
int sum_of_square(int a, int b);
int bigger_num(int a, int b);
int two_more_bigger_sum_of_square(int a, int b, int c);
int smaller_num(int a, int b); //check the code
int main()
{
cout<<two_more_bigger_sum_of_square(,,);
return ;
}
int square(int x) {
return x*x;
} //retun the sum of the num of square
int sum_of_square(int a, int b) {
return square(a)+square(b); } //return the bigger num
int bigger_num(int a, int b) {
if (a > b)
return a;
else
return b;
} //takes the two num as agrument and return the smaller num
int smaller_num(int a, int b) { //return the bigger num
if (a > b)
return b;
else
return a;
}
scip习题(1) scheme和c实现的对比的更多相关文章
- the little schemer 笔记(0)
the little schemer 笔记 Z.X.L 2012年08月13日 五项规则 car的规则car只对非空列表有定义. cdr的规则cdr只对非空列表有定义.任何非空列表的cdr是另外一个列 ...
- SCIP读书笔记(1)
这书也算是必修吧,尤其是我这种非科班人员,还是应该抽时间尽量学习一下.大致翻过一遍,习题非常多,尽力吧. ##构造过程抽象 * 为了表述认知,每种语言都提供了三种机制:基本元素:组合方式:抽象方法. ...
- SICP 习题 (1.10)解题总结
SICP 习题 1.10 讲的是一个叫“Akermann函数”的东西,去百度查可以查到对应的中文翻译,叫“阿克曼函数”. 就像前面的解题总结中提到的,我是一个数学恐惧者,看着稍微复杂一点的什么函数我就 ...
- scip学习
最近在学习scip 准备把里面比较有价值的题分别用lisp和c语言写出来.这样或许能更加深入的理scheme的函数式编程. tip:我用的c语言环境是vs2015,lisp环境为Drracket;
- 开始学习Scheme
开始学习Scheme 函数式编程(Functional Programming)是在MIT研究人工智能(Artificial Intelligence)时发明的,其编程语言为Lisp.确切地说,L ...
- Python 函数习题
#encoding=utf-8 from urllib.request import urlopen import random import os ''' 1. 定义一个fuc(url, folde ...
- SCIP:构造过程抽象--面向对象的解释
心智的活动,除了尽力产生各种简单的认知之外,主要表现为如下三个方面:(1)将若干简单认知组合为一个复合的认识,由此产出各种复杂的认知.(2)将两个认知放在一起对照,不管他们如何简单或者复杂,在这样做时 ...
- Partition:Partiton Scheme是否指定Next Used?
在SQL Server中,为Partition Scheme多次指定Next Used,不会出错,最后一次指定的FileGroup是Partition Scheme的Next Used,建议,在执行P ...
- Android业务组件化之URL Scheme使用
前言: 最近公司业务发展迅速,单一的项目工程不再适合公司发展需要,所以开始推进公司APP业务组件化,很荣幸自己能够牵头做这件事,经过研究实现组件化的通信方案通过URL Scheme,所以想着现在还是在 ...
随机推荐
- JavaScript实例技巧精选(10)—计算器实例2
>>点击这里下载完整html源码<< 这是截图: 利用Javascript和html实现的另一个计算器实例,核心代码如下: <script language=" ...
- Matlab中如何用命令方式保存图像?
命令很简单,例如下面这个代码将当前图像保存到F1.emf文件中,保存格式为emf saveas(gcf,'F.emf','emf'); 当然了,也可以保存为jpg格式,修改为: saveas(gcf, ...
- PLAN : 入门题目 ( update )
更新后 step 1 : A07, A11, A12,A14,A15,A18,A22,A24,A25,A26 A27,A29,A31,A32,A34,A59,A66,A69,A84,B24 B45,B ...
- C# STA和MTA线程设置
参考资料: http://www.yesky.com/20010207/158097.shtml http://www.ftponline.com/china/XmlFile.aspx?ID=242 ...
- Jumony Core 3,真正的HTML引擎
Jumony Core 3,真正的HTML引擎,正式版发布 2013-11-28 17:22 by Ivony..., 778 阅读, 18 评论, 收藏, 编辑 Jumony是一个开源项目,已经有三 ...
- asp.net mvc部署
GAC 目录: 在运行窗口中输入:C:\WINDOWS\assembly\GAC NET 2.0,3.0 GAC: c:\windows\assembly (32bit and 64bit?) .NE ...
- DES加密解密帮助类
public class DESCrypto { /// <summary> /// 初始化des实例秘钥及向量 /// </summary> /// <param na ...
- VMware NAT方式 CentOS 6.8配置静态IP
一.打开虚拟机设置,配置网络连接,如下图 二.编辑 /etc/sysconfig/network,以配置网关 vim /etc/sysconfig/network NETWORKING=yes HOS ...
- jquery.post用法补充(type设置问题)
jquery.post用法 http://blog.csdn.net/itmyhome1990/article/details/12578275 当使用ajax获取data数据的时候,直接data.f ...
- nginx-push-stream模块源码学习(三)——发布
一.概述 发布:发布者将MSG post到某一特定通道上,channel将信息缓存 在说明发布流程之前有必要说明下channel和msg的数据结构. 二.数据结构 2.1 MSG 发布 ...