top of page

Making Structs in Verse, Simplified

  • Writer: N/A
    N/A
  • Sep 22, 2025
  • 1 min read

In Verse, structs are a clean way to group related data together. They’re great for representing objects with multiple properties, and they can even have operator overloads to make your code more expressive.


Here’s a FruitBasket that holds counts of fruit and a total weight:

FruitBasket<public> := struct<concrete>:
	Apples : int = 0
	Oranges : int = 0
	Bananas : int = 0
	BasketWeight : float = 0.0        

Operator Overloads

We can define operators to make combining baskets or scaling them up easier.


# Add two baskets together
operator'+'<public>(A : FruitBasket, B : FruitBasket)<transacts> : FruitBasket =
    {
        return FruitBasket	{
            Apples := A.Apples + B.Apples,
            Oranges := A.Oranges + B.Oranges,
            Bananas := A.Bananas + B.Bananas,
            BasketWeight := A.BasketWeight + B.BasketWeight
        					}
    }

1 Comment


Phyllida Bentley
Phyllida Bentley
Mar 28

This struct approach in Verse looks neat and practical. Operator overloads definitely enhance code readability and ease of use. Curious how it handles more complex data types! excel online practice

Like
bottom of page