Search code examples
inheritancelispscheme

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?


Solution

  • 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.