首页 > 其他 > 详细

SICP1.3 MIT(CLT) Scheme实现(Lisp)

时间:2014-12-25 22:05:24      阅读:358      评论:0      收藏:0      [点我收藏+]


题目要求给出的函数需要完成以下三件事:

  1. 写一个函数,接受三个数作为参数
  2. 判断三个数中较大的两个数
  3. 计算较大两个数的平方和(两个数的平方之和)

我们从后往前,一步步完成这三个任务。

CSDN没有Lisp。用Python的标记了

#lang racket
;;SICP 1.3

;;try 1
(define (square x)(* x x))
(define (sum x y)(+(square x)(square y)))
(define (sum-largest x y z)
  (cond ((= (min x y z) x) (sum y z))
        ((= (min x y z) y) (sum x z))
        ((= (min x y z) z) (sum x y))))
;;try 2
(define (largest-three x y z)
  (if (>= x y)
      (sum x (if (>= y z) y z))
      (sum y (if (>= x z) x z))))
;;testing 1
(sum-largest 2 3 6)
(sum-largest 5 8 12)

;;testing 2
(largest-three 4 8 75)


SICP1.3 MIT(CLT) Scheme实现(Lisp)

原文:http://blog.csdn.net/p641290710/article/details/42154415

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!