jueves, 1 de octubre de 2015

My first post on Ada

Well...it might be my fist post on Ada but it's not my first encounter with Ada -;) I learned it about 10 years ago or more...but until now...I didn't give to much of a use...

If you're wondering...what's Ada? Well...according to Wikipedia...

Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages.

So yes...it pretty much looks like Pascal...but way more strict...and complex...

As usual with my "My first post on..." I build a Fibonacci List generator...something simple to start re-learning the language...so here it goes...

fibonacci.adb
with Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Fibonacci is
 package IO renames Ada.Text_IO;
 package Number_IO is new Ada.Text_IO.Integer_IO (Integer);
 num : Integer;
 
 function Fib(num:Integer;a:Integer;b:Integer) return Unbounded_String is
 result : Unbounded_String;
 begin
  if a > 0 and num > 1 then
   result := result & Integer'Image(a+b) & " " & Fib(num-1,a+b,a);
  elsif a = 0 then
   result := Integer'Image(a) & " " & Integer'Image(b) & " " & 
             Integer'Image(a+b) & " " & Fib(num-1,a+b,b);
  end if;
  return result;
 end Fib;
 
begin
 IO.Put("Enter a number: ");
 Number_IO.Get(num);
 IO.Put(To_String(Fib(num,0,1)));
end Fibonacci;

And here are the screenshots...



Well...that's was fairly easy...but of course I needed to investigate a little bit...so the challenge will be when I start working on my LED Numbers app... -:P

Greetings,

Blag.
Development Culture.