ID:134335
 
Are if() and goto procs or not? The DM reference says they are and I agree. Some other people seem to disagree though. I'd really like definitive points, relating directly to DM (as opposed to other programming languages), rather than opinions.
DeathAwaitsU wrote:
Are if() and goto procs or not? The DM reference says they are and I agree. Some other people seem to disagree though. I'd really like definitive points rather than opinions.

They are clearly statements or, more specifically, clauses. They are just actions that cause a jump in code flow based on the value of an expression. Just because if() has parentheses doesn't make it a function.

Hiead
Scenario.

You're writing a programming language, and you need to add if. Do you make it a function, with function-like attributes, or do you make it a statement, with statement-like attributes? The latter is true. Consider:

The if is like so:
if( condition ) { true_stmt; } else { false_stmt; };

Now, the if itself is an actual statement which translates to: "condition == True." However, it's slightly more advanced, because it also determines what to execute next. This is internal functionality. The if itself just judges the statement, then the program figures out which to execute next: true_stmt or false_stmt.
In response to Audeuro (#2)
Audeuro wrote:
You're writing a programming language, and you need to add if. Do you make it a function, with function-like attributes, or do you make it a statement, with statement-like attributes? The latter is true.

What? Just because you say so?

Now, the if itself is an actual statement which translates to: "condition == True." However, it's slightly more advanced, because it also determines what to execute next.

Nothing follows after a statement (as a result of the statement).

The if itself just judges the statement, then the program figures out which to execute next: true_stmt or false_stmt.

The if() proc evaluates the expression then the syntax jumps to the statement to execute based on what if() returns.
In response to DeathAwaitsU (#3)
DeathAwaitsU wrote:
Are if() and goto procs or not? The DM reference says they are and I agree. Some other people seem to disagree though.

Sounds like the DM reference needs to be fixed, then, because they are most definitely not procs. if() could be confused for a proc since it uses parentheses, but it is just a statement, like for(), while(), and spawn(). (There's an odd one for you: spawn() is a statement, but sleep() is a proc.) goto is quite obviously not a proc at all, because it doesn't even use the parenthetical notation.

Statements:

if
for
while
goto
return
call
spawn
new
del

Note that new and del are not to be confused with New(), and Del(), the procs they call.

Lummox JR
As many have stated, if is not a proc.

Excel has an if() function, it is formated as follows:
if (this=that, truevalue, falsevalue)


As you can see, that follows a (mostly) function format. But BYOND's if() does not, as it does far more than what is stated in the ().

goto is clearly not a proc because it goes far above the level of any proc, built in or user made. It cuts through the code in an almost illogical way.
In response to Lummox JR (#5)
Lummox JR wrote:
(There's an odd one for you: spawn() is a statement, but sleep() is a proc.)

That doesn't sound odd to me. sleep() makes sense to be a proc; have the calling function wait for a call to sleep() to return, based on the argument passed in. spawn() would branch off and execute the other code (presumably in another thread?) after a certain delay.

Hiead
Statements, because that's what they are -- things that conditionally control the flow of code. =)

Procs are things which do not tend to directly affect the flow of code. sleep() is an "exception" in that it does upset the flow of code, but it does so in a certain fashion that is theoretically distinct from statements.

"Statement" is generally defined as any action within the code you are writing. A proc on its own line is considered a statement -- a "procedure call". The proc itself, however, is very much a proc, by definition, which contains statements of its own. =)
In response to Hiead (#1)
In scripting languages, such as ruby, we would call if, for, while, else, elseif, switch, spawn, etc. "Block-level statements".

Of course, "scripters" are not *REALLY* programmers to the T, so we have a strange vocabulary. =P
In response to Ter13 (#9)
Ter13 wrote:
Of course, "scripters" are not *REALLY* programmers to the T

Nonsense. =)

Scripting may be easier than, say, C++ programming, but that doesn't mean it's not "real programming".