Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Scheme++

Name: Anonymous 2012-06-16 15:57

I'm implementing Scheme dialect with OOP, default argument values and some other features. How readable is it for you?

(define (fib n (memo . #{ (0 . 1) (1 . 1) }))
  (let ((memoized (: memo get n)))
    (if memoized (cdr memoized)
        (let ((result (+ (fib (- n 1)) (fib (- n 2)))))
          (: memo set! (n . result))
          result))))

Name: Anonymous 2012-06-17 5:47

>>12
but I want to be able to distinguish between function call and object's method call.

why?


[1]> (defclass A () ())
#<STANDARD-CLASS A>
[2]>
(defclass B () ())
#<STANDARD-CLASS B>
[3]>
(defclass C () ())
#<STANDARD-CLASS C>
[4]>
(defmethod poly ((a A))
  1)
#<STANDARD-METHOD (#<STANDARD-CLASS A>)>
[5]>
(defmethod poly ((b B))
  2)
#<STANDARD-METHOD (#<STANDARD-CLASS B>)>
[6]>
(defmethod poly ((c C))
  3)
#<STANDARD-METHOD (#<STANDARD-CLASS C>)>
[7]>
(map 'list #'poly (map 'list #'make-instance '(A B C)))
(1 2 3)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List