Some questions about environments (from post #4)

I’ve been trying to debug some quite complicated code I wrote, featuring calls to procedures stored in variables a.o. One of these procedures is apparently sometimes called with an unexpected parameter value, but I haven’t succeeded in discovering which other part of the software is actually calling it, and what the caller’s variable settings are. Ideally I would like to reverse the order of evaluation from where I encountered the issue, but I’m afraid that’s impossible.

What I suspect to be doable is having the caller’s variable names and values reported, perhaps the caller’s block label, or even similar data about the caller’s caller (etc.). Does anyone have tools for this kind of thing? And / or any other generally useful debugging tools? Thx!

By the way, here are mine. (not all blocks are debugging tools, but several are).

You can actually stick a pause block before the block in question, then right click the pause block, and you'll see a list of variable names that you can click on to show the watcher on stage (and to hide temporary variable watchers, just run hide variable [] with the slot empty).

Of course you can also use visible stepping to see the results of reporters, and step through the code.

@ego-lay_atman-bay: thanks, but one of my issues is too complicated for that.

So I made a block that finds all variables that are visible within a specified environment, and attaches their values:

This version adds a labeled record of variables and their current values to a log:

Unresolved questions

  1. What I have not figured out yet, is whether one can find the label of the current block, or its caller. Does anyone know?
  2. How can I distinguish between local variables and variables from an outer scope, especially if a local variable bears the same name as an outer variable? (granted, I could invent tricks to find out, like changing the value of a variable and then read the values; but that may be more complicated than necessary).
  3. Finally (for now) I would like to know if (and how) one can get to the caller of a given environment. What I tried that doesn’t work is:

… and this is what it reports:

  1. Doesn't this work for you?
    label1
    and this:
    label2

  2. Why? What are you trying to do? How about dealing with inputs:


    and you can also get their values:

    and even map them to a dictionary:

    You can do the same with variables in nested scopes:

    and compare them across scopes:

    which also lets you filter them by scope, e.g. to only get the inner ones:

    but ... again, why?

  3. I think the above also answer this question: Ringify it!

Does that help?

untitled script pic (64)

  1. Yes, this works for me - thanks! What I’ve been trying to do (and achieved now, using your suggestion) is write a block that will report the name (or label) of the procedure it’s embedded in (e.g. for debugging purposes):



streams alt multi script pic 8

  1. Yeah, I catch your drift. What I’m ultimately trying to achieve is to write a procedure logging all variables associated with any procedures within the call stack, plus their values. I’m going to try to build that now.

  2. That works for me, too.

@dardoro: thanks for the insight, too!

cool! I'm glad it helped and am curious where this leads up to :slight_smile:

As I wouldn’t want any variable quoted twice, I developed this test for sameness of two variables:

Explanation and demo
Within this demo, the inner a is a separate variable from the outer a, whereas there’s only one b.
The streams alt multi script pic 13 block will detect this difference by temporarily changing the value of one variable, testing whether the “other” variable contains the same (unique) value, and finally restoring the original value(s). The warp will protect the critical section, making sure no other process is changing (any of) the variable(s).

I still think it’s a bit of a complicated test procedure, and wonder if it could be simplified.

I finally built the procedure I’ve been looking for:

… building on:

Demo

(N+, results count, etc. are global variables; log is a global varaible, too, but it is not reported so as to prevent data explosion)