Skip to content

Conversation

Folcon
Copy link

@Folcon Folcon commented Aug 19, 2021

This is to support nrepl's eval which states that:

:ns The namespace in which to perform the evaluation.
The supplied namespace must exist already (e.g. be loaded).
If no namespace is specified the evaluation falls back to *ns* for the session in question.

Documented here:
https://github.com/nrepl/nrepl/blob/master/doc/modules/ROOT/pages/ops.adoc#eval

Some additional notes:

  • I'm not 100% certain if the use of eval :ns is supposed to actually change the current *ns* value, I don't believe it's supposed to. If it is supposed to change the current *ns* value, then line 212, can be deleted.
    Otherwise the code below will need to be inserted somewhere to create this effect:
// We need to return the ns to the prior value
if (priorNs != null)
{
	// Debug.Log("Current ns: " + fileNs.ToString());
	evalBindings = evalBindings.assoc(RT.CurrentNSVar, priorNs);
}
  • Additionally I've written some statements that I believe should be true =)... Sorry if it's not 100% bit tired at this point ;)...

    Things that should work!

  1. Does calling an unqualified function within a namespace invoke it within that namespace?

Load in this file:

(ns game.core
  (:require [arcadia.core :as arc])
  (:import [UnityEngine GameObject]))

(defn log-name [obj role-key]
  (arc/log (.name obj)))

(def main-object (atom nil))

(defn create-main []
  (if-let [main-obj (arc/object-named "Main")]
    (reset! main-object main-obj)
    (swap! main-object (fn [n] (new UnityEngine.GameObject "Main")))))

(defn hook-main []
  (arc/hook+
    @main-object
    :start
    :log-name
    ;; in log-name `obj` will be the `the-object`, `role-key` will be `:log-name`
    #'log-name))

Then eval the below within the comment block in that same namespace!

Having evaled this:

(do
  (in-ns 'user)
  (defn create-main []
    (println "THIS IS THE WRONG ONE!"))

  (defn hook-main []
    (println "THIS IS THE WRONG ONE!")))

Then this:

(ns-publics 'game.core)

should give:

{main-object #'game.core/main-object,
 create-main #'game.core/create-main,
 hook-main #'game.core/hook-main,
 log-name #'game.core/log-name}

and evaling this:

(create-main)

should not give:

THIS IS THE WRONG ONE!
=> nil

But instead give:

=> #<Main (UnityEngine.GameObject)>
  1. Calling (in-ns 'some.namespace) should change the namespace to some.namespace.

This must work, evaling the below:

(do
    (in-ns 'user)
    (defn hook-main []
      (println "THIS IS THE WRONG ONE!")))

should produce in the REPL:

=> #'user/hook-main

This currently doesn't work:

(identity *ns*)
=> #object[Namespace 0xaf89a000 "game.core"]
(in-ns 'game.fishing)
=> #object[Namespace 0x74822e00 "game.fishing"]
(identity *ns*)
=> #object[Namespace 0xaf89a000 "game.core"]

The *ns* should have changed to game.fishing, but stays as game.core as that was the namespace it was called from. Directly entering it into the REPL will change the namespace.

  1. Evaling code within a different namespace shouldn't change the current namespace.
    (I'm not 100% certain this is correct behaviour)

Finally, this is all a bit rough and ready, I just wanted to get a conversation started about what it needs to look like and make sure this implementation doesn't cause issues with other implementations =)...

Folcon added 2 commits August 19, 2021 23:58
… the namespace

This is to support nrepl's eval which states that:
:ns The namespace in which to perform the evaluation.
The supplied namespace must exist already (e.g. be loaded).
If no namespace is specified the evaluation falls back to *ns* for the session in question.

Documented here:
https://github.com/nrepl/nrepl/blob/master/doc/modules/ROOT/pages/ops.adoc#eval
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

Successfully merging this pull request may close these issues.

1 participant