Questions tagged [multimethod]
90 questions
0
votes
0 answers
How to extend a function without changing the function itself
I'm curious if I could augment/extend the functionality of a base function using functools techniques.
I'm putting together a module with many methods returning generators, and I'm looking for an effective way to dispatch them (?) and also provide…

Le Chase
- 170
- 9
0
votes
2 answers
Why Common Lisp CLOS matches on a method where the arguments are the wrong class?
I am trying to learn CLOS and bumped into this surprise. I have those 3 action methods that seemingly incorrectly match on my arguments. When I run tryme function, why the action marked with the last argument being ':c' does not trigger the expected…

ruby_object
- 1,229
- 1
- 12
- 30
0
votes
1 answer
How to dispatch methods of a superclass?
I would like to decorate the shapely.geometry.Point class to instantiate it from a dendropy.datamodel.basemodel.AnnotationSet object. I chose the multimethod package to dispatch __init__ of the superclass as it dispatches this method into a simple…

Vovin
- 720
- 4
- 16
0
votes
1 answer
"'module' object is not callable" when I decorate a function with the multimethod decorator in AWS Lamba
I'm getting an issue where lambda throws a "'module' object is not callable" error when I decorate a function with the multimethod decorator. I created an arbitary example to recreate this issue.
import json
from multimethod import…

Ozymandias
- 839
- 1
- 8
- 13
0
votes
0 answers
Replacing methods with multimethods
In a new project, instead of defining methods inside the bodies of my classes, I would like to use multimethods exclusively and define nothing inside my classes except for data members.
In other words, instead of this:
class A():
x: int = 0
…

lambdakappatheta
- 145
- 1
- 5
0
votes
2 answers
Multimethod / dispatch functions based on keyword argument names in Python
EDIT #1: I have updated the example with a "manual" if/else based solution as suggested to demonstrate the need for further automation.
How to efficiently dispatch functions (i.e. implement something like multimethods) where the target function is…

simfinite
- 59
- 4
0
votes
2 answers
Clojure multimethod on class OR keyword
Suppose I have this multimethod
(defmulti m (fn [v] [(:type v)]))
(defmethod m [Object] [k] (prn "Object"))
(defmethod m [:mykwd] [k] (prn "mykwd"))
When I call it with subclass of Object, it correctly dispatches to the first implementation:
(m…

Konrad Garus
- 53,145
- 43
- 157
- 230
0
votes
2 answers
Multimethod dispatch on namespaced map namespace
Is it possible to dispatch based on a namespaced map namespace i.e. #:{}? Without hacks like printing or inspecting key prefixes?
I consider the last one hacky because a key prefix can be overridden:
(:qux/bar #:qux{:bar :baz}); =>…

JAre
- 4,666
- 3
- 27
- 45
0
votes
0 answers
How is multimethod selection being used in this java example?
class HelloWorld{
public static void main(String []args){
A j = new B();
B k = new B();
System.out.println(j.foo(k));
}
}
class A {
public int foo(A p) { return 1; }
}
class B extends A {
public int foo(A p) {…

tsquared
- 99
- 2
- 14
0
votes
3 answers
C++ multimethods and compile time detection
I have the following code :
class A{};
class B: public A{};
class C: public A{};
class MyVisitor
{
public:
void visit(B*);
void visit(C*);
};
And then collection of A* objects, I want to achieve the following :
1)
MyVisitor…

user152508
- 3,053
- 8
- 38
- 58
0
votes
2 answers
Multi-method in Clojure not returning expected value
I am working through the Joy of Clojure book and am now on the multi-methods section. In that book they give an example that is supposed to return one thing, but returns another for me (I have tried both LightTable and Emacs). The code is a little…

kurofune
- 1,055
- 12
- 26
0
votes
1 answer
Why does't my variables stay in order from method to method?
I use the bubble sort method to sort the input numbers in order (least to greatest), and I have it in its own method. Then, in the next method (where I need to have the numbers in order) it seems to ignore that I have sorted the numbers out in the…

ToonLink
- 235
- 1
- 2
- 9
0
votes
2 answers
How to use type hinting to create a Clojure multimethod with a variable number of args?
I'm trying to use type hinting to differentiate between two single-arg methods.
For example, add-vertex is wrapping a Java method that can take a variable number of args, and so here I am trying to make add-vertex take zero, one, or two…

espeed
- 4,754
- 2
- 39
- 51
-1
votes
1 answer
Anylogic: Queue decision making of Agents
I am working on a model for my thesis about attraction visiting decision-making of tourists in Anylogic. How can I give the visitors (agents) varying maximum waiting times. So that if a queue of an attraction exceeds this waiting time, the visitor…

jeroenb
- 1
-2
votes
1 answer
Static (compile time/strictly typed) multi-dispatch support in C#
I recently found myself using the same pattern over and over in my code. Basically it is a variation of visitor pattern that I use to resolve references to instances of base classes to derived ones. This approach requires lots of boilerplate…

Trident D'Gao
- 18,973
- 19
- 95
- 159