Handlers/Functions with or without ( )

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Nonsanity
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 86
Joined: Thu May 17, 2007 9:15 pm
Contact:

Re: Handlers/Functions with or without ( )

Post by Nonsanity » Fri Nov 08, 2013 5:56 pm

I think this discussion has pretty much wrapped up for all parties concerned, but I wanted to point out one other feature of the language that makes function parenthesis important. And that is: you can have a function and a command with the same name. If for no other reason, the parenthesis make it possible for both the language and us poor humans to tell the difference at a glance.

Code: Select all

on mouseUp
   ATest 123            -- This calls the command
   get ATest            -- THIS puts the string "ATest" into the variable it!
   get ATest(123)       -- This calls the function
-- get ATest 123        -- This won't compile since it would be unclear as to which to use, the function or the command
end mouseUp

on ATest x              -- The command
   answer "ATest command" & return & x
end ATest

function ATest x        -- The function
   answer "ATest function" & return & x
   return x
end ATest
Oh, and do NOT do this. This is bad bad bad. Use distinct names! :D
~ Nonsanity
~ Chris Innanen

Post Reply