Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance classes in Scheme

Now I research OOP-part of Scheme. I can define class in Scheme like this:

(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))

(Example from css.freetonik.com)

Can I implement class inheritance in Scheme?

like image 260
AndreyAkinshin Avatar asked Jan 26 '26 21:01

AndreyAkinshin


1 Answers

Well, I wouldn't call that a class, but that's just me. That's simply closures and raw scheme.

Scheme itself does not have an object system. However, Scheme is capable of implementing a class system.

If you would like to use an oop system, there are several written for Scheme that you can try.

Here is a link that lists several, there are certainly others.

like image 126
Will Hartung Avatar answered Jan 29 '26 13:01

Will Hartung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!