Call a function: Difference between revisions

Content added Content deleted
imported>J7M
(add example for SmallBASIC)
Line 6,117: Line 6,117:
macro definition is responsible for evaluating what it needs to. But macros likely
macro definition is responsible for evaluating what it needs to. But macros likely
fall into a different category than the scope of this task.
fall into a different category than the scope of this task.

=={{header|SmallBASIC}}==
<syntaxhighlight lang="basic">
func F1()
return 1
end

func F2(a)
return a + 1
end

func F3(a, b)
return a + b
end

func F4(byref a)
a = 5
return a + 1
end

sub S1(a, b)
print a, b
end

sub S2(byref a)
a = 5
end

var1 = 1
var2 = 2

' Functions return a result and return-value must be assigned to a variable
result = F1()
result = F2(var1)
result = F3(var1, var2)
' Parameters are passed by reference if byref is used in function definition
result = F4(var1) ' result = 6 and var1 = 5

' Subroutines can't return a result
S1(var1, var2)
' Parameters are passed by reference if byref is used in sub definition.
' This can be used to return a result indirectly
S2(var1) ' var1 = 5

' Functions and subroutines can take expressions as parameter
result = F2(1 + 2)
</syntaxhighlight>



=={{header|Smalltalk}}==
=={{header|Smalltalk}}==