How do you see the full "called from" chain of function calls after an error? - gap-system

Upon getting an error in the GAP command line interpreter, the chain of function calls that led to the error get's truncated, so I can see the start of the chain, which is the function I'd need to fix.
gap> MyAwesomeFunction(x,y);
Error, resulting list would be too large (length infinity) called from
ConstantTimeAccessList( enum ) at /path/to/gap/lib/coll.gi:506 called from
AsList( l ) at /path/to/gap/lib/list.gi:612 called from
AsPlist( l ) at /path/to/gap/lib/list.gi:673 called from
EnumeratorSorted( Enumerator( D ) ) at /path/to/gap/lib/domain.gi:231 called from
EnumeratorSorted( C ) at /path/to/gap/lib/coll.gi:862 called from
... at line 4 of *stdin*
you can 'quit;' to quit to outer loop, or
you can 'return;' to continue
brk>
How do I tell GAP to show me the full chain of functions here? What's behind that ...?

As per Alexander Konovalov's comment, the Where function is the key here. Entering Where(42) in the break look will show up to 42 functions in this "called from" chain.

Related

Function iMA is returning different return value from expected (MQL5)

I'm using MQL5 (my first code).
I want to use a script that uses MA, but first, I wanted to confirm the value to verify I'm doing correctly. Using a very basic code into script:
double x=0;
x = iMA(Symbol(),Period(),100,0,MODE_SMA,PRICE_CLOSE);
Alert("The actual MA from last 100 points of EURUSD actually is: " + x;
The expected value is near the actual price... 1.23456, but this function is returning 10.00000 or 11.0000.
I believe I'm missing something, and https://www.mql5.com/es/docs/indicators/ima helplink is not quite clear enough.
I already saw another similar function: MA[0] which seems to bring the moving average from specific candle, but, I don't know how to manage the Period range (100) or if is related to Close/Open variables on it. I didn't find any specific helplink to review.
Any ideas are very appreciated!!!
x should be int, it is a handler of the MA. So each indicator when created in MT5 receives its handler, and you can use it later to get what you need. If you need several MA's - create several handlers and give each of them different names (x1, x2 or add some sense). Expert advisors in the default build of MT5 are good examples on what to do.
The iMA function Returns the handle of a specified technical indicator, not the "moving average" value.
For example, to get the value of the Moving average you can use this (in MQ4):
EMA34Handler = iMA(NULL,0,34,0,MODE_EMA,PRICE_CLOSE);
EMA34Value = CopyBuffer(EMA34Handler, 0,0);

Binary Search Tree traverse method, what makes it go up from lowest left child(leaf)?

I have a hard time understanding how the SearchTree "traverse in order method" goes up after it reaches the most left leaf. I UNDERSTAND that at first root becomes leftchild, than down 1 level leftchild again, again, until it becomes the lowest left leaf, which has no left child and no right child. OK. But how does it go level up after the root is the last leaf. What is the EXACT line of code that makes the traverse method go one level up from the lowest left child. Since for that node both root.leftchild and root.rightchild are null. This is magic to me.
public void inOrderTraverseTree(Node root) {
if (root != null) {
inOrderTraverseTree(root.leftChild);
System.out.println(root);
inOrderTraverseTree(root.rightChild);
}
}
This is because of the property of the recursive function which returns to it parent calling function after getting executed.
e.g.
20
/ \
10 30
this is a tree with its root as 20. Now walking through the inOrderTraverseTree code of yours:
1. call inOrderTraverseTree(20)
2. check for root being null, here 20 is not null.
3. call inOrderTraverseTree(10) {left of 20 is 10}
4. check for root being null, here 10 is not null.
5. call inOrderTraverseTree(null) {left of 10 is null}
6. check for root being null, here it is null.Hence exit out of "if",return to calling function,i.e step 4{root=10}
7. print root,i.e print 10.
8. call inOrderTraverseTree(null) {right of 10 is null}
9. check for root being null, here it is null.Hence exit out of "if",return to calling function,i.e step 3{root=20}.{complete execution for root=10 is completed}
10.print root,i.e print 20.
11.call inOrderTraverseTree(30){right of 20 is 30}
12.check for root being null, here 30 is not null.
13.call inOrderTraverseTree(null){left of 30 is null}
14. check for root being null, here it is null.Hence exit out of "if",return to calling function,i.e step 12{root=30}
15. print root,i.e print 30.
16. call inOrderTraverseTree(null) {right of 30 is null}
17. check for root being null, here it is null.Hence exit out of "if",return to calling function,i.e step 11{root=20}.{complete execution for root=30 is completed}
with this the complete execution of inOrderTraverseTree call with root 20 is also completed and the value printed is 10 (in step 7), 20 (in step 10), 30 (in step 15): 10 20 30.
Now coming to "code that makes the traverse method go one level up from the lowest left child" : you can see this happening in step 9. Where the leftmost child is returned to its parent calling function when the complete function cycle for leftmost child is fully executed. This is the main property of recursive function.
Imagine you've a stack, and every call to inOrderTraverseTree(Node root) being stored in the stack through some pointer(if you don't know what a pointer is, imagine there's a variable that represents a function call).
So, if inOrderTraverseTree(Node root) is called n times, the stack will have n pointers to the function.
What you're asking is, what'll happen after n calls? Well, the answer is, we return to the function that was previously called. This is done by removing the pointer at the top of the stack. Now, what we'll have at the top of the stack is the pointer to the previous function call.
In short, every time a recursive call is made, a pointer to the function is pushed to the stack. Once we reach the end of traversal, we start the popping elements from the stack one-by-one.
Since this operation involves push & pop only, this is the very reason a stack is being to store function calls.

Live variable analysis , is my explanation correct?

As stackexchange have not more tags about compiler tags , so I'm posting here , this question .
A variable x is said to be live at a statement Si in a program if the following three conditions hold simultaneously :
1. There exists a statement Sj that uses x
2. There is a path from Si to Sj in the flow
graph corresponding to the program
3. The path has no intervening assignment to x
including at Si and Sj
The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
p, s, u
r, s, u
r, u
q, v
I try to explain :
As the wikipedia says "Stated simply: a variable is live if it holds a value that may be needed in the future."
As per the definition given in question, a variable is live if it is used in future before any new assignment.
Block 2 has ‘r’ and ‘v’ both as live variables. as they are used in block 4 before any new value assinged to them. Note that variable ‘u’ is not live in block 2 as ‘u’ is assigned a new value in block 1 before it is used in block 3. Variables ‘p’, ‘s’ and ‘q’ are also not live in block 2 due to same reason.
Block 3 has only ‘r’ as live variable as every other variable is assigned a new value before use.
Another explanation given as :
Only r.
p, s and u are assigned to in 1 and there is no intermediate use of them before that. Hence p, s and u are not live in both 2 and 3.
q is assigned to in 4 and hence is not live in both 2 and 3.
v is live at 3 but not at 2.
Only r is live at both 2 and 3.
But official GATE key said both r and u.
I see two things that are probably at least part of your confusion.
First, in the list of conditions for live variables, there is no restriction stating that Si != Sj, so this makes the definitions a little imprecise in my mind.
The second is your assertion "Note that variable ‘u’ is not live in block 2 as ‘u’ is assigned a new value in block 1 before it is used in block 3."
The way I would look at this would be this:
Upon entry into block 2, before the statement v = r + u is
executed (imagine a no-op empty statement inserted as the entry to
each block, and another as the exit from the block), then both r
and u must be live, because there exists an upcoming statement
that uses both, and there is a path in the code from the entry to
that statement that contains no intermediate assignments to either.
Rather than imagining these extra empty statements, using the
original semantics of the definitions, then we're just talking about
the case where Si == Sj, because both refer to the v = r + u
statement - there is trivially a path from a statement to itself
containing no additional assignments in that sense. I find it easier
to think about it with the extra empty entry and exit statements,
though.
After the execution of v = r + u, however, at the imaginary
block exit empty statement, it is now safe to consider u as not
live (alternatively, dead), because nothing in block 4 uses it, and
it's reassigned in block 1 before it's ever used again in either
block 2 or 3.
So, part of the confusion seems to be thinking of whether a variable is live in a particular block, which doesn't really fit with the definitions - you need to think about whether a variable is live at the point of a particular statement. You could make the case that the variable u is both alive and dead in block 2, depending on whether you look at it before execution of the lone statement, or after...

Can't get my for loops to work

Okay, so I'm trying to have the program do three steps...
1: choose a number between (m,n) which are parameters being passed in (Set to variable "repeat")
2: choose a random number between 0 and the variable "repeat" from step one. (Set to variable "o")
3: subract "o" from "repeat" and set that result to variable "p"
thus I get a number (lets say 100)
then a random number from 0-100 (lets say 40)
and then I get the difference of 100-40 (60...)
I then want the program to run a for loop "o" (40) times and another for loop "p" (60) times...
the code for the for loops section looks like this (keep in mind there is more code before this... It just doesn't really pertain to this question:
def randomStars(pic,m,n):
repeat=random.randint(200,300)
o=random.randint(0,repeat)
p=repeat-o
for i in o:
star(pic,x,y)
for j in p:
largeStar(pic,x,y)
show(pic)
What's happening is I'm getting an error message on the line:
for i in o:
that says "iteration over non-sequence
inappropriate argument type
I've also added print statements after the 3 variables are set and they are working...
ex.1 repeat=230; o=103; p=127
ex.2 repeat=221; o=72; p=149
and then I immediately try to get the for loop to run "o"number of times and I get the above error message... I don't see how it is a non-sequence. But perhaps I'm simply not understanding the definition of a sequence
o and p are integers. For for loops you need something that is iterable. I thing you can change it to:
for i in range(o):
This is range() documentation for Python 2.x

Parameter 3 is not constant in call of system task $fwrite

I am using Xilinx ISE 10.1 to run some verilog code. In the code I want to write the register values of 3 registers in a file, cipher.txt. The following is the code snippet:
if (clk_count==528) begin
f1 = $fopen("cipher.txt", "w");
$fwrite(f1, "clk: %d", clk_count[11:0]);
$fwrite(f1, "plain: %h", plain[31:0]);
$fwrite(f1, "cipher: %h", cipher[31:0]);
$fclose(f1);
end
At the end of execution, the contents of cipher.txt is found as:
clk: %dplain: %hcipher: %h
There is no other error encountered, but a warning comes up corresponding to the 3 fwrite's:
Parameter 3 is not constant in call of system task $fwrite.
Parameter 3 is not constant in call of system task $fwrite.
Parameter 3 is not constant in call of system task $fwrite.
The values of the registers clk_count and cipher change on every clock cycle (value of register plain remains constant throughout), and the values are written to cipher.txt when clk_count equals 528 (indicated by the if statement)
Can anybody provide some insight and/or help me get past this hurdle?
Thanks.
It appears that ISE expects the arguments to $fwrite to be constant. The warnings are referring to clk_count[11:0], plain[31:0], and cipher[31:0], which are not constant. By definition they are changing each cycle so they are not known at compile time. This also explains why they are not printing and you are seeing %d and %h in the output.
There is nothing to my knowledge in the Verilog spec that requires the arguments to $fwrite be constant. The same code works as expected with Cadence Incisive. My guess is that it's a limitation of ISE, so you may want to check with Xilinx.
Possible work-arounds:
1) Use $swrite to create a string with the proper formatting. Then write the string to the file.
2) Try using an intermediate variable in the calls to $fwrite. Maybe the part-selects are throwing it off. e.g.
integer foo;
foo = clk_count[11:0];
$fwrite(... , foo , ...);
Either of those might work, or not.
Out of curiosity, if you remove the part-selects, and try to print clk_count without the [11:0] , do you get the same warnings?