Yorick
http://yorick.sourceforge.net/phpBB3/

Random_seed initialization
http://yorick.sourceforge.net/phpBB3/viewtopic.php?f=6&t=405
Page 1 of 1

Author:  marksutton [ Tue Dec 17, 2013 4:05 pm ]
Post subject:  Random_seed initialization

Random_seed behaves differently when called as a function or as a subroutine. I am not sure if this is the expected behaviour. I am running yorick 2.2.02x. The following demonstrates this difference (starting in a fresh yorick):
Code:
> random(1)
[0.0891647]
> random_seed,.123
> random(1)
[0.162779]
> random_seed(.123)
> random(1)
[0.0891647] //since gives initial random number, it is like seed is out of range.
> random_seed,.123
> random(1)
[0.162779]   //works when called as a subroutine.

I would have guessed that calling random_seed as a function would return the current random seed.

Author:  ThiĆ©baut [ Wed Dec 18, 2013 11:51 pm ]
Post subject:  Re: Random_seed initialization

Hello,

The problem is that Y_random_seed drops all its arguments and left nothing on top of the stack so when you call it as a function (without storing the result in a variable) the interpreter "displays" the result (the topmost stack item) which is the function itself and thus re-execute random_seed without any argument this time which reset the seed to a default value as you correctly guessed.

The fix is easy: just discard:
Code:
Drop(nArgs);
at the last line of function Y_random_seed in std1.c (line number 1120). Then the result of calling random_seed will be its argument (whatever it is). Another possibility could be to push a boolean (scalar int) to indicate whether the call was successful or not.

I am not allowed to push changes into Yorick repository so I left Dave decides if it is worth fixing this bug...

Author:  munro [ Fri Dec 20, 2013 8:07 pm ]
Post subject:  Re: Random_seed initialization

Commit 58b3486 "fixes" this. It is still an error to invoke random_seed as a function, but now its return value is its input instead of the function itself.

Just to make it clear what's going on, here's an interpreted function that acts like random_seed used to:

Code:
> func yo(x) { "yo"; return yo; }
> yo
"yo"
> yo(.123)
"yo"
"yo"
> yo,.123
"yo"
> print,yo(.123)
"yo"
func yo(x)
>

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/