Thread View: net.math.stat
2 messages
2 total messages
Started by Rolf Turner
Tue, 27 Nov 1984 06:55
S for-loops.
Author: Rolf Turner
Date: Tue, 27 Nov 1984 06:55
Date: Tue, 27 Nov 1984 06:55
16 lines
954 bytes
954 bytes
Try the following in S: > a<-1:5 > for(i in a) print(i) > for(i in 0+a) print(i) > for(i in a) print(i) The results which I get seem mystical & mystifying. I'd appreciate hearing if anomalies occur at other installations (or if the mystery is peculiar to ours). Also explanations and/or fixes would be welcomed. Address (in case the header is incomprehensible): ....decvax!mulga!rolf:natmlab
Re: S for-loops.
Author: Rick Becker
Date: Thu, 15 Nov 1984 11:18
Date: Thu, 15 Nov 1984 11:18
41 lines
2108 bytes
2108 bytes
> Try the following in S:
>
> > a<-1:5
> > for(i in a) print(i)
> > for(i in 0+a) print(i)
> > for(i in a) print(i)
>
>
> The results which I get seem mystical & mystifying. I'd appreciate hearing
> if anomalies occur at other installations (or if the mystery is peculiar to
> ours). Also explanations and/or fixes would be welcomed.
>
You have found a bug. Fortunately the fix is simple. Change the
file $M/funev.r as follows:
50c50,52
< if(intern) { #clear up the stack, keeping only the function value
---
> if(intern & !streq(TEXT(fname),TSTRING(newblt))) {
> # clear up the stack, keeping only the function value
> # newblt must not have its storage freed
and then reload the executive. That should fix things.
-----
The reason for the bug is that whenever an internal function is
executed funev tries to free-up any storage the internal function may
have used. "for(i in a)" invokes the newblt() function giving it as
one of its arguments a DATASET entry named "a". $M/gtinst is called by
infun when trying to evaluate newblt, and it is the routine that
actually reads the dataset. newblt puts the pointer to the data on the
stack, but when it returns, funev pops the stack and the space that
once contained the dataset is now free to be overwritten by anything
else that wants it. If the expression in the for() is a computed
expression rather than a dataset name, the expression is already on the
stack, and hence it is not bothered by the freeing operation.
--
Rick Becker alice!rab research!rab
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads