I was under the impression that call by reference was default in pike, but it seems I've lived a lie. Is there a way to write
void foo(string s) { s=s+"!"; }
void main() { string a = "Hello World"; foo(a); write(a+"\n"); }
without returning a string from foo?
It's call-by-reference insofar that the string isn't copied in the call to foo(), but it's not call-by-reference in the sense that modifying a formal argument also modifies the actual argument variable in the caller.
http://pike.ida.liu.se/generated/manual/ref/chapter_3.html#3
That's what was lurking at the back of my head anyway.
this phrase? the assignment operator (=) does not copy anything when you use it on a pointer type.
mind the conditional :-) string, int and float are not pointer types.
greetings, martin.
Yes, use a value that you can modify destructively.
void foo(mapping m) { m->s=m->s+"!"; }
void main() { mapping m=(["s":"Hello World"]); foo(m); write(m->s+"\n"); }
/ Mirar
Previous text:
12527646 2004-11-03 19:54 /14 lines/ Peter Lundqvist (disjunkt) Recipients: Pike (-) help Subject: call by reference
I was under the impression that call by reference was default in pike, but it seems I've lived a lie. Is there a way to write
void foo(string s) { s=s+"!"; }
void main() { string a = "Hello World"; foo(a); write(a+"\n"); }
without returning a string from foo?
(12527646) /Peter Lundqvist (disjunkt) /----------------------------
pike-devel@lists.lysator.liu.se