gpt4 book ai didi

Scheme 中的继承类

转载 作者:太空宇宙 更新时间:2023-11-03 18:44:17 26 4
gpt4 key购买 nike

现在我研究 Scheme 的 OOP 部分。我可以像这样在 Scheme 中定义类:

(define (create-queue)
(let ((mpty #t)
(the-list '()))

(define (enque value)
(set! the-list (append the-list (list value)))
(set! mpty #f)
the-list)

(define (deque)
(set! the-list (cdr the-list))
(if (= (length the-list) 0)
(set! mpty #t))
the-list)

(define (isEmpty)
mpty)

(define (ptl)
the-list)

(define (dispatch method)
(cond ((eq? method 'enque) enque)
((eq? method 'deque) deque)
((eq? method 'isEmpty) isEmpty)
((eq? method 'print) ptl)))

dispatch))

(示例来自 css.freetonik.com)

我可以在Scheme中实现类继承吗?

最佳答案

好吧,我不会把它称为一个类,但那只是我。这只是闭包和原始方案。

Scheme本身没有对象系统。但是,Scheme 可以实现类系统。

如果您想使用 oop 系统,可以尝试为 Scheme 编写的几种系统。

Here是一个列出了几个的链接,当然还有其他的。

关于Scheme 中的继承类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2382082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com