understanding ash call() function example on the wiki

Bale

Minion
Agreed. That code makes no sense. Would anyone care to come up with an example which actually make sense?

Maybe something like...

Code:
string bale() {
   return "Coding scripts is awesome!";
}

string darzil() {
   return "Must spade so that I can improve KoLmafia.";
}

string lostcalpolydude() {
   return "It's tough being the only sane dev on KoLmafia.";
}

string name = my_name();
string raisondetre = call string name();
print(raisondetre);

Okay, that is a terrible example, but it is fun and works for those three players.
 

Ulti

Member
Does
Code:
"hello world".print();
do anything?
It prints a log to the command line
Same as:
Code:
print("hello world")
or from the command line:
Code:
ash print("hello world")
but the example on the wiki is corrupted code since the function "hello world" doesn't exist.
I think the example on the wiki is supposed to read:
Code:
string a = "print";
call a( "hello world" );
but this isn't a very good usage of call's potential. Bale gave us one possible example.
Something closer to its intended purpose would be something like:
Code:
boolean apply(string fn,boolean[string] args)
{
	string[int] arg;
	int i=0;
	foreach key in args
	{
		arg[i]=key;i+=1;
	}
	switch(arg.count())
	{
		case 0:call fn();return true;
		case 1:call fn(arg[0]);return true;
		case 2:call fn(arg[0],arg[1]);return true;
		case 3:call fn(arg[0],arg[1],arg[2]);return true;
		case 4:call fn(arg[0],arg[1],arg[2],arg[3]);return true;
	}
	return false;
}

"print".apply($strings[Testy (this is black)]);
"print".apply($strings[hello (this is red),red]);
"print".apply($strings[world (this is blue),blue]);
 

Veracity

Developer
Staff member
I remember implementing this.

Code:
r6603 | veracity0 | 2008-12-10 09:43:28 -0500 (Wed, 10 Dec 2008) | 5 lines

Add experimental "call" feature to ASH to invoke a function whose name is
determined at runtime, not parse time.

------------------------------------------------------------------------
r7120 | veracity0 | 2009-03-27 14:45:34 -0400 (Fri, 27 Mar 2009) | 6 lines

Soup up ASH's "call" facility a bit: in addition to accepting a string variable
reference to hold the function to invoke, allow a parenthesized expression that
evaluates to a string.
I don't remember why; it was a long time ago! I assume there was some discussion here that prompted it. Perhaps if we could find the discussion that lead to this being implemented on Dec 10, 2008 - or my (presumed) announcement of the feature, it might shed some light on the motivation.
 

xKiv

Active member
but the example on the wiki is corrupted code since the function "hello world" doesn't exist.
I think the example on the wiki is supposed to read:
Code:
string a = "print";
call a( "hello world" );

Note that it's actually "print 1" (not just "print") in the wiki example, which is another difference. But I bet whoever wrote that example thought it would work just like the "object.method" syntax ... and either it doesn't (super likely - how would ASH tell which string is the function name and which is the parameter?), or it couldn't because "print 1" also isn't a function.
 

Bale

Minion
I remember implementing this. I don't remember why; it was a long time ago! I assume there was some discussion here that prompted it. Perhaps if we could find the discussion that lead to this being implemented on Dec 10, 2008 - or my (presumed) announcement of the feature, it might shed some light on the motivation.

It was in response to a request of mine. Strangely, it never got used for the purpose I originally intended, but I am happily using it in two other scripts, so thank you.
 

Ulti

Member
I remember implementing this.

Code:
r6603 | veracity0 | 2008-12-10 09:43:28 -0500 (Wed, 10 Dec 2008) | 5 lines

Add experimental "call" feature to ASH to invoke a function whose name is
determined at runtime, not parse time.

------------------------------------------------------------------------
r7120 | veracity0 | 2009-03-27 14:45:34 -0400 (Fri, 27 Mar 2009) | 6 lines

Soup up ASH's "call" facility a bit: in addition to accepting a string variable
reference to hold the function to invoke, allow a parenthesized expression that
evaluates to a string.
I don't remember why; it was a long time ago! I assume there was some discussion here that prompted it. Perhaps if we could find the discussion that lead to this being implemented on Dec 10, 2008 - or my (presumed) announcement of the feature, it might shed some light on the motivation.

http://kolmafia.us/showthread.php?1...-given-a-reference&p=9021&viewfull=1#post9021

Seems the example on the wiki is a corrupted example which attempted to alter your code but instead edited the wrong string and meant to write:
Code:
a = "print";
 
call a( "hello world" );
 
Last edited:
Top