Catamorphism: Difference between revisions

Double entry of uBasic/4tH - moved to proper entry
(Added uBasic/4tH version)
(Double entry of uBasic/4tH - moved to proper entry)
Line 509:
 
 
==={{header|uBasic/4tH}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="uBasic/4tH">For x = 1 To 5 : @(x-1) = x : Next ' initialize array
' try different reductions
Print "Sum is : "; FUNC(_Reduce(_add, 5))
Print "Difference is : "; FUNC(_Reduce(_subtract, 5))
Print "Product is : "; FUNC(_Reduce(_multiply, 5))
Print "Maximum is : "; FUNC(_Reduce(_max, 5))
Print "Minimum is : "; FUNC(_Reduce(_min, 5))
 
End
' several functions
_add Param (2) : Return (a@ + b@)
_subtract Param (2) : Return (a@ - b@)
_multiply Param (2) : Return (a@ * b@)
_min Param (2) : Return (Min (a@, b@))
_max Param (2) : Return (Max (a@, b@))
 
_Reduce
Param (2) ' function and array size
Local (2) ' loop index and result
' set result and iterate array
d@ = @(0) : For c@ = 1 To b@-1 : d@ = FUNC(a@ (d@, @(c@))) : Next
Return (d@)</syntaxhighlight>
{{Out}}
<pre>Sum is : 15
Difference is : -13
Product is : 120
Maximum is : 5
Minimum is : 1
 
0 OK, 0:290 </pre>
==={{header|Yabasic}}===
{{trans|Run BASIC}}
374

edits