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-19 23:00

>>25

If you used (object 'method-name-literal args ...) instead, then you could have a variable represent a method name, and there would be more purity and flexibility in the object. IE, it can be considered as just another closure. Consider calling the following on a vector of objects of the same type:


(define (vectorize-fns fns-vector)
  (lambda args
    (vector-map (lambda (fn) (apply fn args))
                fns-vector)))


So now say you have a vector of objects that implements some interface, IExample, and then you apply vectorize-fns to this vector and store the result in B. B will be an object that implements each method in IExample, but the return value of each method with be vectored.

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