parameter/method

So, I've seen quite a few uses of things like...
Code:
int i=1337;
string s=i.to_string();

So, does variable.function() work only for a defined few? Or just any function whose first parameter is of the same type? Or only functions with 1 parameter?

Just curious.
 
variable.function() calls function(variable). variable.function(variable2) calls function(variable,variable2). I think you should be able to extrapolate from there.
 
Whenever I edit a script with that type of function calls I change them into the function()-only versions because they confuse me, a lot. None of the programming languages I've used have had that sort of function call :)
 
It's done in java. Considering that mafia runs in java I suspect it just seemed natural when ash was being created.

Yes, I've gathered that much as well :)
During my, limited I admit, period of working with programming I've used Fortran, C/C++ (very little) and Matlab none of which use this. I might get used to reading it if I look at more of them but I very much doubt I'll use them myself :)
 
I use variable.function() style of writting when I chain more than one functions:
Code:
int skill_num = 6001;
int skill_amount = skill_num.to_skill().to_effect().have_effect();
is clearer to me than:
Code:
int skill_num = 6001;
int skill_amount = have_effect( to_effect( to_skill( skill_num ) ) );
 
Last edited:
And in that example, the bottom is so much clearer to me... it just makes more sense to my math side. Parenthesis means that the thing inside is affected by the outside. :D
 
And in that example, the bottom is so much clearer to me... it just makes more sense to my math side. Parenthesis means that the thing inside is affected by the outside. :D

I totally agree :)
It feels abit more like I am going from right to left, just like when I'm reading rather than going from left to right evaluating until I get to the start of the line.
 
It feels abit more like I am going from right to left, just like when I'm reading rather than going from left to right evaluating until I get to the start of the line.
I didn't understand this ^^
I thought from the first part that it was natural for you to read from right to left, but then I don't understand the second part.

Using variable.function1().function2() seems more natural to me exactly because it is more like reading. What would be the start of the line to me is the variable, and the end of the line is what it is processed into after going through the various functions.

In any case, it's a purely subjective point of vue, the end result is the same anyway.
 
As a mathematician by degree I much prefer the "second" choice. I note the similarity of notation to function composition where (g o f)(x) == g(f(x)).
 
I didn't understand this ^^
I thought from the first part that it was natural for you to read from right to left, but then I don't understand the second part.

Using variable.function1().function2() seems more natural to me exactly because it is more like reading. What would be the start of the line to me is the variable, and the end of the line is what it is processed into after going through the various functions.

In any case, it's a purely subjective point of vue, the end result is the same anyway.

function1(function2(variable)) is much more like reading to me since I start with what function1 does on function2 on the variable rather than the opposite which is what the variable does in function1 in function2.
Also, it is as has been stated more similar to the mathematics I am used to as an engineer.
 
I guess that kind of makes me way off base. I use both. Heck, I've used both like to_skill(something).to_effect()

... I don't remember if I've ever cleaned that up. Great, now I've gotta go get OCD on my scripts.
 
I can see how func(func(func(param))) might make more sense to a math person since you wouldn't see much x.sqrt().power(2) but the other method will make more sense once you get used to object oriented coding since you wouldn't want to do something like string s="5"; append(append(s,"start"),"ing") when you could s="5".append("Start").append("ing");

Basically I use the second method when it is obvious that it applies to the variable starting the chain, and the second method otherwise.
 
I imagine that most ASH programs resemble "<program/script as implied subject> <verb> <object> <object>" and so I'd agree with the assessment of our resident mathematicians -- in ASH, it should be a lot more natural to write/read conventional function calls rather than leverage implied first parameters.

That said, I added dot notation (or Java style, as it's described on the wiki) thinking that people using ASH records could write code that was object oriented if they wanted to. The only way to verify that people were actually taking advantage of this language feature in this fashion is if you see people write functions where the first parameter was named 'this' and refer to it that way in the function body.

However, I do not believe the language feature has ever been used like that. Instead, it's likely only been used by people who take advantage of the reduced number of ending closing parentheses, which is primarily relevant to people writing ASH using an editor or a font that doesn't help them figure out which function call is having its parameter list terminated by the parenthesis they just added.
 
Back
Top