Parameters for functions and commands

Mike Kerner MikeKerner at roadrunner.com
Thu Jan 4 17:41:51 EST 2018


I agree that the syntax should be the same.  the parenthesis difference is
annoying
Then there's the way RETURN is handled in functions as opposed to handlers
(vs RETURN FOR VALUE and RETURN FOR ERROR)

On Thu, Jan 4, 2018 at 4:57 PM, Bob Sneidar via use-livecode <
use-livecode at lists.runrev.com> wrote:

> In short, yes. Commands can still pass parameters, and as you may not know
> CAN ALSO RETURN VALUES. The difference is that functions are called with
> parenthesis and must be put into a variable. eg.
>
> function bobtest 1, 2
>    -- do some stuff
>    return true
>    -- do some other stuff
> end bobtest
>
> Now I can say:
>
> put bobTest(1, 2) into tBobResult -- if you exclude into tBobResult the
> result will be put into the message
>
> Commands are simply called and then the result variable contains anything
> put there by the return command ie.
>
> on bobtest2 pParam1, pParam2
>    -- do some stuff
>    return true
>    -- do some other stuff
> end bobtest2
>
> Now I can say:
>
> bobtest 1,2 -- or dispatch "bobtest" to card 1 with 1,2
> put the result into tBobResult
>
> NOTE: when a return command is encountered, either in a command or
> function, the handler is immediately exited and control is returned to the
> calling handler. So anything after -- do some other stuff WILL NOT EXECUTE.
>
> I suppose the difference may be somewhat academic, but as a convention,
> functions are usually used to get information, process it and return values
> without actually "doing" anything, like going to a card or putting values
> into fields etc. Commands actually DO things, but nothing is preventing you
> from using all commands or all functions. You can see though from the above
> examples that functions are slightly simpler to code with, requiring one
> line instead of two to process returned values. It can also make code more
> readable:
>
> put theInternetDate(the date) into tToday
> updateTheRecordDate tToday
>
> Bob S
>
> > On Jan 4, 2018, at 13:30 , Thomas von Fintel via use-livecode <
> use-livecode at lists.runrev.com> wrote:
> >
> > I am well aware that I shouldn't expect *everything* in Livecode to be
> intuitive, but this one bugs me:
> >
> > Having a handler like
> >
> >    function DoStuff_1 a, b
> >
> >       return a
> >
> >    end DoStuff_1
> >
> > When you do "put DoStuff_1 (2,3)" the result is 2.
> >
> > But with
> >
> >    on DoStuff_2 a, b
> >
> >        put a
> >
> >    end DoStuff_2
> >
> > The result of DoStuff_2 (2, 3) is 2,3. "put a*b" produces an error.
> >
> > This means, parameters are passed differently to command handlers and
> function handlers. Right?
> >
> > Is that the way it should be and why?
> >
> >
> > Thanks for your patience
> >
> > Thomas
> >
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."



More information about the use-livecode mailing list