Computer Science Canada Why can't a function be in a procedure? |
Author: | Kharybdis [ Fri Jan 04, 2008 6:09 pm ] |
Post subject: | Why can't a function be in a procedure? |
My friend has made a slime game, and, in tribute to his slime game, i ask the question - in his slime game, a function cannot be in a procedure. Is there any way to get past that? |
Author: | HeavenAgain [ Fri Jan 04, 2008 6:19 pm ] |
Post subject: | RE:Why can\'t a function be in a procedure? |
why make a function in a procedure.... how does that work a function is a function and a procedure is a procedure, you make them separately, and call to them separately |
Author: | Tony [ Fri Jan 04, 2008 6:43 pm ] |
Post subject: | RE:Why can\'t a function be in a procedure? |
a procedure is a function that returns void. If your program calls for defining a function inside of another function, then something is very wrong. |
Author: | Clayton [ Sat Jan 05, 2008 1:08 pm ] |
Post subject: | RE:Why can\'t a function be in a procedure? |
This concept is not entirely unheard of. However, not being an expert on the subject, a better person to ask would be wtd. |
Author: | TokenHerbz [ Sat Jan 05, 2008 1:29 pm ] | ||
Post subject: | Re: Why can't a function be in a procedure? | ||
Your asking if a function can be inside a procedure? Quote: a function cannot be in a procedure.
Well it can, Here take a look!
But you know, i don't think thats what you where asking was it???? |
Author: | OneOffDriveByPoster [ Sat Jan 05, 2008 3:50 pm ] |
Post subject: | Re: RE:Why can\'t a function be in a procedure? |
Clayton @ Sat Jan 05, 2008 1:08 pm wrote: This concept is not entirely unheard of. However, not being an expert on the subject, a better person to ask would be wtd. If we are talking about defining functions/procedures inside another function/procedure, then there is no reason except that the language designers decided not to allow that. Indeed, GCC supports nested functions as an extension to C and Pascal has nested functions and procedures. |
Author: | Zampano [ Sat Jan 05, 2008 5:32 pm ] |
Post subject: | Re: Why can't a function be in a procedure? |
Wasn't it that a function can be anywhere, except that when a function or procedure is placed within another, the function or procedure that is being called in the other has to have been declared at an earlier stage is the program? If the multiply function in your example is placed after the procedure, it will fail. As long as the function has been declared beforehand, you can call them arbitrarily. The rule of having an object (is that the right word?) known at compile is common. It stops people from doing stuff like records that have themselves as source or something . . . I think. |
Author: | Tony [ Sat Jan 05, 2008 8:42 pm ] |
Post subject: | Re: Why can't a function be in a procedure? |
Zampano @ Sat Jan 05, 2008 5:32 pm wrote: the function or procedure that is being called in the other has to have been declared at an earlier stage is the program?
Well you could forward your functions, so that's not really a problem. My concern has to do with the scope. If a function is defined within another function, former will have a scope, local to the latter. Maybe there's a practical counter-example to this, but I would think that if a single function is large enough to require a local function just for itself, then the design could be refactord. |
Author: | ericfourfour [ Sat Jan 05, 2008 8:52 pm ] | ||||||
Post subject: | Re: Why can't a function be in a procedure? | ||||||
I haven't posted here in a while, but I thought I'd help out with this one. I can't really thing of a scenario where one would define a function inside a procedure but there are a few alternatives to this. One is if you want to introduce another scope within the procedure. The other is if you want to use a certain namespace. If you want to introduce another scope, use the begin/end commands.
If you want to add a namespace look into modules. The purpose of modules in Turing is to add a namespace.
You can even have nested modules.
It should be noted that calling procedures from a nested module will cause a run-time warning. The program will still run however. Functions do not cause this problem. |
Author: | Kharybdis [ Sun Jan 06, 2008 11:50 am ] |
Post subject: | Re: Why can't a function be in a procedure? |
Thank you everyone ![]() ![]() |