2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,7 +1,14 @@
|
|||
A function is a body of code that returns a value.
|
||||
|
||||
The value returned may depend on arguments provided to the function.
|
||||
|
||||
|
||||
;Task:
|
||||
Write a definition of a function called "multiply" that takes two arguments and returns their product.
|
||||
|
||||
(Argument types should be chosen so as not to distract from showing how functions are created and values returned).
|
||||
|
||||
See also:[[Function prototype]]
|
||||
|
||||
;Related task:
|
||||
* [[Function prototype]]
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
MULTIPLY: STX MULN ; 6502 has no "acc += xreg" instruction,
|
||||
TXA ; so use a memory address
|
||||
MULLOOP: DEY
|
||||
CLC ; remember to clear the carry flag before
|
||||
ADC MULN ; doing addition or subtraction
|
||||
CPY #$01
|
||||
BNE MULLOOP
|
||||
RTS
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
// One-liner
|
||||
fun multiply(a: Int, b: Int) = a * b
|
||||
|
||||
// Proper function definition
|
||||
fun multiplyProper(a: Int, b: Int): Int {
|
||||
return a * b
|
||||
}
|
||||
1
Task/Function-definition/Maple/function-definition.maple
Normal file
1
Task/Function-definition/Maple/function-definition.maple
Normal file
|
|
@ -0,0 +1 @@
|
|||
multiply:= (a, b) -> a * b;
|
||||
|
|
@ -1 +1 @@
|
|||
@list.grep( -> $obj { $obj.substr(0,1).lc.match(/<[0..9 a..f]>/) )
|
||||
@list.grep( -> $obj { $obj.substr(0,1).lc.match(/<[0..9 a..f]>/) } )
|
||||
|
|
|
|||
4
Task/Function-definition/Processing/function-definition
Normal file
4
Task/Function-definition/Processing/function-definition
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
float multiply(float x, float y)
|
||||
{
|
||||
return x * y;
|
||||
}
|
||||
3
Task/Function-definition/SETL/function-definition.setl
Normal file
3
Task/Function-definition/SETL/function-definition.setl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
proc multiply( a, b );
|
||||
return a * b;
|
||||
end proc;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
BEGIN
|
||||
INTEGER PROCEDURE multiply(x, y);
|
||||
INTEGER x, y;
|
||||
BEGIN
|
||||
multiply := x * y
|
||||
END;
|
||||
Outint(multiply(7,8), 2);
|
||||
Outimage
|
||||
END
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
@(do (defun mult (a b) (* a b))
|
||||
(put-line `3 * 4 = @(mult 3 4)`))
|
||||
(defun mult (a b) (* a b))
|
||||
(put-line `3 * 4 = @(mult 3 4)`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue