問題タブ [multimethod]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
clojure - 異なる名前空間の別々のファイルにマルチメソッドを実装する
マルチメソッドとその実装を別のファイルで定義しようとしています。次のようになります: ファイル 1 内
ファイル 2 で
そして、メソッドを呼び出すときにメインファイルで次のように定義します。
これを行うと、例外が発生します"No method in multimethod 'foo'for dispatch value: hello
私は何を間違っていますか?それとも、別のファイルでマルチメソッドの実装を定義することはできませんか?
common-lisp - メソッドによる :after の呼び出しを停止する
以下のようなコード設定があるとします
ここで、宇宙船をステーションに移動したいとしますが、燃料計算の結果、船の燃料がマイナスの量になります (つまり、移動に十分ではありません)。
:after
必ずしもエラー状態を通知せずに修飾子が呼び出されないようにする方法はありますか?
私が電話を止めなければ、船は燃料を差し引かずに新しい場所に移動し、本質的にゲームが中断されます.
clojure - clojureでマルチメソッドメタデータを設定および取得するには?
コマンドラインコマンドとその引数を解析するためにマルチメソッドを使用しています。
特定のメソッドのメタデータにアクセスしようとすると、clojure は以下を返しますnil
。
clojure - Using Clojure multimethods defined across multiple namespaces
Although the below example seems a bit strange, it's because I'm trying to reduce a fairly large problem I've got at present to a minimal example. I'm struggling to work out how to call into multimethods when they're sitting behind a couple of abstraction layers and the defmulti and corresponding defmethods are defined in multiple namespaces. I really feel like I'm missing something obvious here...
Suppose I've got the following scenario:
- I purchase stuff from a variety of suppliers, via their own proprietary interfaces
- I want to implement a common interface to talk to each of those suppliers
- I want to be able to purchase different items from different suppliers
Using Clojure, the recommended ways of implementing a common interface would be via protocols or multimethods. In this case, as I'm switching based on the value of the supplier, I think the best way to handle the situation I'm describing below is via multimethods (but I could be wrong).
My multimethod definitions would look something like this, which defines a common interface I want to use to talk to every supplier's APIs:
For each supplier, I probably want something like:
and
So far, no problem
Now to my code which calls these abstracted methods, which I assume looks something like:
This is starting to look a bit ... ugly. Every time I implement a new supplier's API, I'll need to change myapp.suppliers.api to :require that new supplier's methods and recompile.
Now I'm working at the next level up, and I want to buy a widget from supplier2.
This can't work, because :supplier2 hasn't been defined anywhere in this namespace.
Is there a more elegant way to write this code? In particular, in myapp.core, how can I buy-something from :supplier2?
java - このJavaの例では、マルチメソッド選択はどのように使用されていますか?
したがって、印刷される出力は 2 になります。これがどのように行われるのかわかりません。j
オブジェクトはコンパイルされた形式とは見なされませんかA
? それでも、コンパイル時と実行時の両方でクラスのクラスであっても、型パラメーターを使用するクラスB
バージョンを実行します。これはなぜですか?foo
A
k
B
common-lisp - 関数は複数のディスパッチ システムで変更可能ですか?
(ほとんどの?いくつかの?)複数のディスパッチ言語では、プログラムの実行のある時点で各メソッドが関数に追加されることを正しく理解しました。
次に、機能としての複数のディスパッチにより、関数が変更可能になると結論付けることができますか?
すべてのメソッドが (ジェネリック) 関数に (ロード時に) 一緒にアタッチされている複数のディスパッチ言語があるので、異なる時点で異なる状態の関数を見ることができませんか?