Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash of keyword is different between runtimes #232

Open
skydread1 opened this issue Sep 3, 2022 · 0 comments
Open

Hash of keyword is different between runtimes #232

skydread1 opened this issue Sep 3, 2022 · 0 comments

Comments

@skydread1
Copy link
Contributor

Problem

The Clojure function related to the error is the following:

(defn valid-cards-ids
  "Returns a list of all the valid cards ids."
  [deck-id & [uuid]] 
  (->> (full-deck deck-id true uuid)
       (map :id)
       set))

The error is actually due to the :id as a function in (map :id)

Calling the function from Unity:

Clojure.GetVar("clojure.core", "map")
    .invoke(RT.keyword(null, "id"), fullDeck)
// => {ChunkedCons}[nil nil nil nil nil nil ...]

In fact, looking at the valAt C# code:

public object valAt(object _param1, object _param2)
{
  object o = _param1;
  switch (Util.hash(o) & 3)
  {
    case 0:
      if (o == (object) Keyword.intern((string) null, "id"))
        return this.id;
      break;
    case 1:
      if (o == (object) Keyword.intern((string) null, "num"))
        return this.num;
      break;
    case 2:
      if (o == (object) Keyword.intern((string) null, "suit"))
        return this.suit;
      break;
    case 3:
      if (o == (object) Keyword.intern((string) null, "deck-id"))
        return this.deck\u002Did;
      break;
  }
  return RT.get(this.__extmap, _param1, _param2);
}

When :id is called, the hash is 1 not 0 as shown above.

So the hash of the keyword :id is different between compiling the valAt of PokerCard and the rumtime calculation.

I directly copied Clojure.dll and Magic.Runtime from my Nostrand to unity assets and got the same results.

So the difference is caused by the different dotnet runtimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant