Diference between "To decide which ... " and "To [+ verb]"


I was wondering, is there a fundamental difference between :

To decide which number is double (input - a number) : decide on input * 2; and

To twice (input - a number) gives (output - a number) : now output is 2 * input; ?

Well. Apparently yes, there is. Because when testing :

Instead of waiting :
	say "[double 2] - ";
	let output be a number that varies;
	twice 2 gives output;
	say "[output].";

I got the result :

Which means that output hasn’t been changed in my second rule…
But, I don’t really understand why, as I had just created a rule “To produce (fact - a factory): …”, which could change components of the factory.
If I was thinking in C, I would think that output has been passed as a value, so I can’t change it. While fact contains the references to its elements, so I can change them.

Is that right ? Any hints there ?

This is roughly equivalent C code:

int double(int x){
    return 2*x;

void twice_gives(int in, int out){
    out = 2*in;

You’re basically right, output is being passed by value rather than by reference, so changing it inside the function doesn’t change it outside the function.

The reason it’s different with your factories is that objects (and all the subclasses of object) are rather like C strings: by their nature, they are always passed by reference in Inform. When you say “there is a book in the Library” that sets aside a certain amount of memory in the file for the book; after that “the book” is a pointer to that memory.

You could also use this sort of idiom:

Doubling is a number based rulebook producing a number.

Doubling a number (called N): rule succeeds with result 2 * N.

Instead of waiting :
	let output be the number produced by doubling for 2;
	say "[output]."


Thank you, this makes things clearer.

@Roger : I haven’t investigated much rulebooks yet.
But, the idea is to perform an action, and know in return if it succeeded (and if not, the reason why). So, it might look cleaner with that “rule succeeds with …”