[gambit-list] Generic functions in 45 lines

Jason Felice jason.m.felice at gmail.com
Mon Apr 22 10:39:06 EDT 2013


Clearly, there could be more features and it could be more efficient, but
in terms of producing the simplest thing that works for me, I'm really
happy with this:

https://gist.github.com/eraserhd/5435505

Usage:

(define-generic (length object))

(add-method (length (vector? v))
  (vector-length s))
(add-method (length (string? s))
  (string-length s))
(add-method (length (list? l))
  (##length l))

(length "hello") => 5
(length '(1 2 3)) => 3
(length '#(a b)) => 2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20130422/26fcfe12/attachment.htm>


More information about the Gambit-list mailing list