How to resolve the algorithm Apply a callback to an array step by step in the FutureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Apply a callback to an array step by step in the FutureBasic programming language

Table of Contents

Problem Statement

Take a combined set of elements and apply a function to each element.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Apply a callback to an array step by step in the FutureBasic programming language

Source code in the futurebasic programming language

include "NSLog.incl"

void local fn Callback( n as NSInteger )
  NSLog( @"Square root of %ld = %f", n, sqr(n) )
end fn

void local fn DoIt
  NSUInteger i, count
  CFArrayRef array = @[@1, @2, @3, @4, @5, @6, @7, @8, @9, @10]

  count = len(array)
  
  for i = 0 to count -1
    fn Callback( fn NumberIntegerValue( array[i] ) )
  next
end fn

fn DoIt

HandleEvents

include "NSLog.incl"

void local fn Callback( array as CFArrayRef, obj as CFTypeRef )
  long value = intVal(obj)
  NSLog( @"Square root of %ld = %f", value, sqr(value) )
end fn

void local fn DoIt
  CFArrayRef array = @[@1, @2, @3, @4, @5, @6, @7, @8, @9, @10]
  ArrayEnumerateObjects( array, @fn Callback, NULL )
end fn

fn DoIt

HandleEvents

  

You may also check:How to resolve the algorithm Stack step by step in the Nim programming language
You may also check:How to resolve the algorithm Walk a directory/Non-recursively step by step in the E programming language
You may also check:How to resolve the algorithm Filter step by step in the Red programming language
You may also check:How to resolve the algorithm Arrays step by step in the HicEst programming language
You may also check:How to resolve the algorithm Atomic updates step by step in the Euphoria programming language