Questions tagged [multimethod]

90 questions
2
votes
1 answer

Python multimethods using isinstance

In this article Guido van Rossum says that this kind of multimethod implementation in Python: def foo(a, b): if isinstance(a, int) and isinstance(b, int): ...code for two ints... elif isinstance(a, float) and isinstance(b, float): …
Mike Vella
  • 10,187
  • 14
  • 59
  • 86
2
votes
3 answers

Clojure multimethods, how to add data?

Firstly, I'm new to Clojure, so this is likely to be stupid question. As a learning exercise, I've got a trivial text adventure multimethod system working. I now want to change from using keywords to some form of 'classiness', which can hold data…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
1
vote
1 answer

How to extend Class::Multimethods::Pure to recognise Moose Roles?

I need multemethod dispatch with Moose objects. I'm doing this with Class::Multimethods::Pure. I chose this instead of MooseX::MultiMethods because it depends on MooseX::Method::Signatures which can't install on my system because it fails its tests.…
stevenl
  • 6,736
  • 26
  • 33
1
vote
0 answers

multilline use of object methods

I have a question that's nagging me. Is it possible to use multiple methods of an instance , without writing the name. I dont mean static methods. Language : java For example: object name bibo of class manager the class has three methods …
McCurtis
  • 11
  • 1
1
vote
1 answer

How is an "isa?" based multimethod more than syntax sugar for instanceof?

I am taking an example from the clojure site. (defmulti foo class) (defmethod foo ::collection [c] :a-collection) (defmethod foo String [s] :a-string) (foo []) :a-collection (foo (java.util.HashMap.)) :a-collection (foo "bar") :a-string This…
Daniel
  • 546
  • 1
  • 6
  • 15
1
vote
1 answer

How to bypass print-method

I have an application with a lot of large maps and other things, which are clumsy to read when printed, so I made a custom print function for them and set up print-method to call it, like this: (defmethod print-method clojure.lang.PersistentArrayMap…
Ben Kovitz
  • 4,920
  • 1
  • 22
  • 50
1
vote
1 answer

Multiple dispatch and multi-methods

What are they, what's the different between them? Many sources, like Wikipedia, claim they're the same thing, but others explicitly say the opposite, like sbi in this question: First: "Visitor Pattern is a way to simulate Double Dispatching in…
peoro
  • 25,562
  • 20
  • 98
  • 150
1
vote
5 answers

Are functions mutable in multiple dispatch systems?

Have I understood correctly that in (most? some?) multiple dispatch languages each method gets added to the function at some point in time of program's execution. Can I then conclude that multiple dispatch as a feature forces functions to be…
Aivar
  • 6,814
  • 5
  • 46
  • 78
1
vote
0 answers

How to set and get multimethod docstring in clojure?

I'm using multimethods to parse command line commands and their arguments. (defmulti run (fn [command args] command)) (defmethod run :default [& _] ...) ^{:args "[command]"} (defmethod run "help" [_ & [args]] "Display command list or help…
Aleksei Zyrianov
  • 2,294
  • 1
  • 24
  • 32
1
vote
1 answer

Clojure defining multimethods and how to pass parameters

I seem to have a hard time understanding how the below code works. And more precisely how the defined function handles passed parameters (defmulti encounter (fn [x y] [(:role x) (:role y)])) (defmethod encounter [:manager :boss] [x y] …
siper92
  • 23
  • 4
1
vote
1 answer

Clojure defmethod Pattern Match Dispatch-Value

I seem to be coming up with too many multi-dispatch functions and would like to reduced the number. The approach I am currently using is to have a multi-function call another multifunction but that seems wrong. Here is an example of what I would…
phreed
  • 1,759
  • 1
  • 15
  • 30
1
vote
1 answer

Clojure multimethod giving unexpected null pointer

I'm having a hard time getting the multimethods in Clojure to work as I would expect. A distillation of my code is as follows. (defn commandType [_ command] (:command-type command)) (defmulti testMulti commandType) (defmethod testMulti :one [game…
Seth Paulson
  • 800
  • 6
  • 15
1
vote
1 answer

Multimethods vs Interfaces

Are there languages that idiomatically use both notions at the same time? When will that be necessary if ever? What are the pros and cons of each approach? Background to the question: I am a novice (with some python knowledge) trying to build a…
1
vote
2 answers

Is it possible to provide multiple different implementations of a multimethod for the same type?

How do I create multiple implementations of a multimethod for a single data type? This may not be a great example, but I hope it illustrates the idea: be able to treat nested vectors both as sequences: repl> (def thing [[[1] []] [27] [18 [32…
Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
0
votes
1 answer

how to use Python multimethod with custom class as argument type

I have the following classes setup: class A: pass class B(A): pass class C(A): pass Then I have a method that gets called with 2 arguments: x -> always a string y -> one of the classes above (A, B, or C) And we do something different…
KSS
  • 147
  • 1
  • 8