sicp每日一题[2.48]

Exercise 2.48

A directed line segment in the plane can be represented as a pair of vectors—the vector running from the origin to the start-point of the segment, and the vector running from the
origin to the end-point of the segment. Use your vector representation from Exercise 2.46 to define a representation for segments with a constructor make-segment and selectors
start-segment and end-segment.


这道题太简单了,没啥说的。

(define (make-segment v1 v2)
  (cons v1 v2))

(define (start-segment segment)
  (car segment))

(define (end-segment segment)
  (cdr segment))


(define v1 (make-vect 3 4))
(define v2 (make-vect -4 3))
  
(define a-segment (make-segment v1 v2))
a-segment
(start-segment a-segment)
(end-segment a-segment)

; 执行结果
(mcons (mcons 3 4) (mcons -4 3))
(mcons 3 4)
(mcons -4 3)
posted @   再思即可  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示