Reply to topic  [ 3 posts ] 
Random_seed initialization 
Author Message

Joined: Tue Oct 25, 2005 11:52 am
Posts: 7
Location: McGill University, Montreal Quebec
Post 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):
> random(1)
> random_seed,.123
> random(1)
> 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.

Tue Dec 17, 2013 4:05 pm
Yorick Guru

Joined: Wed Nov 24, 2004 12:51 pm
Posts: 98
Location: Observatoire de Lyon (France)
Post Re: Random_seed initialization

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:
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...

Wed Dec 18, 2013 11:51 pm
Profile WWW
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post 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:

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

Fri Dec 20, 2013 8:07 pm
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.