Couple of Hollywood Innerworkings questions

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1181
Joined: Sun Feb 14, 2010 7:11 pm

Couple of Hollywood Innerworkings questions

Post by Bugala »

1.

If I have:

Code: Select all

ForEach(Tbl1, Function(NotInUse, Content1)
		ForEach(Tbl2, Function(NotInUse, Content2)
				      EndFunction)
				EndFunction)
Is it a problem that I am using same variable "NotInUse" in both cases, when I am not using them?

Naturally if I would name them both as "ID" and be using that ID in the code that might result in unexpected behavior as the Inner Foreach ID would probably override the outer Foreach ID inside the Inner ForEach?


2.

If I have:

Code: Select all

Function Example(A, B, C)
EndFunction
And Then I might in program do:

Code: Select all

Example()
Example(1, 2)
Example(1, 2, 3, 4)
Is there any problem using any of these cases?
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Couple of Hollywood Innerworkings questions

Post by jPV »

1. No problem there. The NotInUse is a local variable to the function. Even if you change its contents in the inner ForEach, it doesn't affect to the outer ForEach. Both functions have their own local NotInUse variables that aren't accessible anywhere else.

2. No problems there either (as long as you prepare for possible Nil values in the function code).
Example() -> A, B, and C get Nil values
Example(1, 2) -> A = 1, B = 2, C = Nil
Example(1, 2, 3, 4) -> A = 1, B = 2, C = 3, and 4 is discarded.
This is explained here: https://www.hollywood-mal.com/docs/html ... ions_.html
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Couple of Hollywood Innerworkings questions

Post by Flinx »

If I don't understand such things, I always try with DebugPrint.

1:

Code: Select all

Tbl1={1,2,3}
Tbl2={4,5,6}
ForEach(Tbl1, Function(NotInUse, Content1)
                  DebugPrint("Tbl1: ",NotInUse, Content1)	
		  ForEach(Tbl2, Function(NotInUse, Content2)
		                    DebugPrint("  Tbl2: ",NotInUse, Content2)	
                                EndFunction)
                  EndFunction)
The results show that a function argument creates a new local variable and does not overwrite the outer one. (That's what I would have expected from a useful programming language...)
To ignore the NotInUse argument should be no problem.

2:

Code: Select all

Function Example(A, B, C)
    DebugPrint(A, B, C)
EndFunction
Example()
Example(1, 2)
Example(1, 2, 3, 4)
Result:
Nil Nil Nil
1 2 Nil
1 2 3

Seems to be ok.
Bugala
Posts: 1181
Joined: Sun Feb 14, 2010 7:11 pm

Re: Couple of Hollywood Innerworkings questions

Post by Bugala »

Thanks for replies.

I assumed there wouldnt be aproblem using these, but wanted to confirm it to be sure Im not going to suddenly encounter some random behavior when using these.


One more question. Not that I plan to do this even, but just from curiosity of understanding more About Hollywood behavior.

But, for example in MakeButton one of the arguments is Function, and I can make that Function when I am making that button, as example:

Code: Select all

MakeButton(#SIMPLEBUTTON, 1, 100, 100, 200, 200, {OnMouseOut= Function() Return(1+2)})
Now this will effectively make Function being held there.

However, there are two possibilities to use a function.

That I can either have:

Code: Select all

Function Example()
A = 1 + 2
Return(A)
EndFunction

Code: Select all

B = Example()
And this would simply return the RESULT of a Function, in this case number 3. That B would be holding number 3.

But if I instead:

Code: Select all

B = Example
In which case B will be holding the Function itself instead of the answer.

Now To get back to MakeButton and to compare it to this example.

When I use Function() Return(1+2) EndFunction) in MakeButton, then effectively this is same as B holding the Function instead of the result.

But what if I instead of wanting to make a Function when making MakeButton, would instead just want the result (3) then is this doable at all?

I mean, of course I can make that Function outside first and use it there, but what if I for some reason would want to make a function right there from which only result would be saved, is that doable?
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Couple of Hollywood Innerworkings questions

Post by jPV »

I'm not quite getting what you're after there... what it would do if you'd get the result (3) into the wild there?
Bugala
Posts: 1181
Joined: Sun Feb 14, 2010 7:11 pm

Re: Couple of Hollywood Innerworkings questions

Post by Bugala »

As I said, not planning to use it, since I don't quite see any reason why to use it, but was just wondering from Hollywood syntax point of view if it is doable. As in, understanding how it works, might help understand how something else that is actually useful works.
Post Reply