What is the binop_ok() method in Euphoria?

Overview

Sequence variables in Euphoria allow for a number of arithmetic operations on the atom and object variables.

The sequence parameter has special requirements before any arithmetic operation can be performed on it.

Note: The question is how to know if two or more objects can have sequence operations carried out between them. There are laid out rules to know this.

However, there is also an inbuilt function in Euphoria that will do this check.

The binop_ok() method

The binop_ok() method will check if two objects can perform a sequence operation together. If they can, the method returns an integer value of 1. Otherwise, it returns 0.

Syntax

binop_ok(objectA,objectB)

Parameters

  • objectA: This is one of the objects to be checked for sequence operation compatibility with another.

  • objectB: This is the other object.

Return value

This returns an integer value of 1 if the two compared objects are compatible for a sequence operation. Then an integer 0 is returned if they are not.

Example

include std/sequence.e
integer output1, output2, output3
output1 = binop_ok({2,3,4},{7,9,8}) --equal size sequence (1)
output2 = binop_ok({5,6,7,10,22},{7,9,8}) --unequal sized sequence (0)
output3 = binop_ok({7,8,9},10) --atom sequence operation (1)
printf(1,"\n%d",output1)
printf(1,"\n%d",output2)
printf(1,"\n%d",output3)

Explanation

  • Line 2: We include the sequence.e module to use the binop_ok function.

  • Line 4: We declare some integer variables to hold the output of the operation.

  • Lines 6–8: We use the binop_ok() method to check the compatibility of the provided values.

  • Lines 10–12: We print the output to the console.

Free Resources