difference between function and command and sending parameters
Jim Ault
JimAultWins at yahoo.com
Fri Oct 17 12:08:24 EDT 2008
Quick answers:
In Rev you can choose which you want since
function calls {can change the UI or data storage, etc}{return a string
value}
command handlers {can change the UI or data storage, etc}{return a string
value}
Most all programming languages have both types of 'handlers' by different
names
Commands or procedures
Functions or methods
--F
put formatToDollars(32.45) into amtToDisplay
--H
formatAsDollars 32.45, "european commas"
put the result into amtToDisplay
--H
send (" formatAsDollars 32.45, ""e&"european""e) to this card
put the result into amtToDisplay
--F
put "formatToDollars(32.45)" into fcnToExecute
do ( "put "& fcnToExecute &" into amtToDisplay")
answer amtToDisplay
--H
put quote into q
put ("formatAsDollars 32.45, "&q&"european commas"&q) into cmdToExecute
do ( cmdToExecute )
put the result into amtToDisplay
answer amtToDisplay
-------- the above routines call these handlers
--F
function formatToDollars amt
return "$" & amt
end formatToDollars
--H
on formatAsDollars pAmt, pStylle
if pStylle is "european commas" then
replace "." with comma in pAmt
return "commas "& pAmt
else
return "periods "& pAmt
end if
end formatAsDollars
------------------------------------
There are other ways of sending and dealing with params that get to be
rather complicated, but enjoyably so :-)
Hope this helps.
Jim Ault
Las Vegas
On 10/17/08 8:08 AM, "william humphrey" <shoreagent at gmail.com> wrote:
> subject was "question that comes from programming without knowlege"
> I always thought that to pass a parameter with a command it had to be a
> function like.
> function myfunction param
> -- do stuff with the param
> end myfunction
>
>
> but I just realized (from use actually) that you can do:
>
> command mycommand param
> -- do stuff with the param
> end mycommand
>
> and it works just as well. Of course you can also say:
>
> on mycommand param
>
> end mycommand
>
> and I guess "on" is a synonym for "command"
>
> Now (if you're bored and read this far) you can "send" a command to a script
> in another card or stack but you can't send a function.
>
> send mycommand param to card "scripshere" of stack "mystack" works fine.
>
> But you can't send a "do myfunction(param)" to a card so any functions that
> you write have to be in the default stack's script if you want to use them
> all over the place.
>
> So my question is twofold.
>
> 1. How do you send a "do" to a function.
>
> and
>
> 2. why would anyone use the function thing when they can use a command with
> a parameter. What good is a function? I guess when you want multiple
> parameters?
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list