my metamethod protocol is coming together: the first time that a generic function called the correct methods, in the correct order even 馃帀

the protocol supports generic functions with multiple dispatch, using custom parsing of parameters and your own predicates for selecting methods. all of this is specified using generic functions (but is bootstrapped using hacks in the compiler/interpreter)


(add-method! specialiser:get ((spec (is-same rest)) args) (cons args nil))
(add-method! specialiser:compare ((spec1 (is-same rest)) (spec2 (is-same rest))) cmp:eq)
(add-method! specialiser:compare ((spec1 (is-same rest)) spec2) cmp:lt)
(add-method! specialiser:compare (spec1 (spec2 (is-same rest))) cmp:gt)

(def-method! example (a b (c rest)) (list a b c))
(example 1 2 3 4 5) => (1 2 (3 4 5))


re: code 

The above is a syntax-sugared way of how Lisp's `&rest' or Python's `*args' syntax can be defined within the metamethod protocol. In reality, some parts of this are builtin since they are needed to bootstrap the whole method system.

Web 0 0 0
Sign in to participate in the conversation

Mastodon is a server for a federated social network: everyone can run a server if they want to, including me. So this is a Mastodon server for me (Vierkantor) and my friends.