Ada Programming/Algorithms/Chapter 1

Chapter 1: Introduction
The following subprograms are implementations of the Inventing an Algorithm examples.

To Lower
The Ada example code does not append to the array as the algorithms. Instead we create an empty array of the desired length and then replace the characters inside.

To_Lower (C : Character) Character Ada.Characters.Handling.To_Lower; -- tolower - translates all alphabetic, uppercase characters -- in str to lowercase To_Lower (Str : String) String Result : String (Str'); C  Str' Result (C) := To_Lower (Str (C)); ;      Result; To_Lower;

Would the append approach be impossible with Ada? No, but it would be significantly more complex and slower.

Equal Ignore Case
-- equal-ignore-case -- returns true if s or t are equal, -- ignoring case Equal_Ignore_Case (S   : String;      T    : String) Boolean O : Integer := S' - T'; T' /= S'          False;  --  if they aren't the same length, they -- aren't equal I  S'              To_Lower (S (I)) /= To_Lower (T (I + O)) False; ;         ;       ;       True; Equal_Ignore_Case;

|Chapter 1