viernes, 31 de julio de 2015

LED is my new Hello World - Zonnon Time

You knew this was coming...don't you? -;)

So here...I took another approach because Zonnon doesn't have a built-in split command...and also because I'm not sure how to create an array of arrays and because I couldn't make my procedure return an array and then assign it to another array -:(

Still...I'm quite happy with the result -:D

LED_Numbers.znn
module LED_Numbers;

var num, text, concat:string;
var leds:array 10 of string;
var led:array 3 of string;
var i, j, z, len, lenled:integer; 

begin
 leds[0]:=" _  ,| | ,|_| ,";
 leds[1]:="  ,| ,| ,";
 leds[2]:=" _  , _| ,|_  ,";
 leds[3]:="_  ,_| ,_| ,";
 leds[4]:="    ,|_| ,  | ,";
 leds[5]:=" _  ,|_  , _| ,";
 leds[6]:=" _  ,|_  ,|_| ,";
 leds[7]:="_   , |  , |  ,";
 leds[8]:=" _  ,|_| ,|_| ,";
 leds[9]:=" _  ,|_| , _| ,";
 write("Enter a number: ");readln(num);
 len:=num.Length;
 for j:=0 to len - 1 do
  i:=0;
  text:=leds[integer(num[j])-48];
  lenled:=text.Length;
  for z:= 0 to lenled - 1 do
   if text[z] # "," then
    concat:= concat + string(text[z]);
   else
    led[i]:=led[i] + concat;
    concat:="";
    i:= i + 1;
   end;
  end;
 end; 
 writeln(led[0]);
 writeln(led[1]);
 writeln(led[2]);
end LED_Numbers.

Anyway...here are the pictures -;)



Greetings,

Blag.
Development Culture.

My first post on Zonnon

As always...I was looking for new and cool programming languages to learn...and then Mark Teichmann came up with something really nice -;) The Zonnon programming language...

So...what's Zonnon? Zonnon is a general-purpose programming language in the Pascal, Modula-2 and Oberon family...and it's run on .NET/Mono...

It's been a really long time since I used Pascal or Delphi...but...just like riding a bicycle...the knowledge came back as soon I started writing some code -;)

Now...the only problem I have with Zonnon...is that's there's almost no documentation...and what's available is in Russian...so...a lot Google helped me up...


Here's the Fibonacci Numbers app...


Fibo.znn
module Fibo;
var num: integer;
var a, b: integer;

procedure fib (var num, a, b : integer): string;
var result: string;
var ab: integer;
begin
 result := "";
 if (a > 0) & (num > 1) then
  num := num - 1;
  ab := a + b;
  result := result + string(ab) + " " + fib(num, ab, a);
 elsif a == 0 then
  num := num - 1;
  ab := a + b;
  result := string(a) + " " + string(b) + " " + string(ab) + " " + fib(num, ab, b);
 end;
 return result;
end fib;

begin
 a := 0;
 b := 1;
 write("Enter a number: ");readln(num);
 writeln(fib(num,a,b));
 writeln("");
end Fibo.

And a couple of pictures...




I need to keep playing and exploring Zonnon...there's a lot of cool things still hiding from me -;)

Greetings,

Blag.
Development Culture.

jueves, 23 de julio de 2015

LED is my new Hello World - Forth Time

Just as you expected...it's time again for my LED Numbers application...this time...using Forth -:)

The code is a little bit longer that I would have expected...but I guess it's either because I'm still a Forth newbie...or because Forth being a stack based programming language has it's own way of dealing with this kind of application...

Here's the source code...enjoy! -;)

LED_Numbers.fth
VARIABLE picky

: COLLECT_PICKY DUP 1- picky ! ;

: NPICK COLLECT_PICKY 2 * 0 ?DO picky @ PICK LOOP ;

: SPLIT BEGIN DUP WHILE 10 /MOD REPEAT DROP DEPTH ;

: First_Line
  CASE
  0 OF SPACE ." _  " ENDOF 1 OF SPACE SPACE ENDOF
  2 OF SPACE ." _  " ENDOF 3 OF ." _  " ENDOF
  4 OF SPACE SPACE SPACE SPACE ENDOF 5 OF SPACE ." _  " ENDOF
  6 OF SPACE ." _  "ENDOF 7 OF ." _   "  ENDOF 
  8 OF SPACE ." _  " ENDOF 9 OF SPACE ." _  " ENDOF
  ENDCASE ;
  
: Second_Line
  CASE
  0 OF ." | | " ENDOF 1 OF ." | " ENDOF
  2 OF SPACE ." _| " ENDOF 3 OF ." _| " ENDOF
  4 OF ." |_| " ENDOF 5 OF ." |_  " ENDOF
  6 OF ." |_  "ENDOF 7 OF SPACE ." |  "  ENDOF 
  8 OF ." |_| " ENDOF 9 OF ." |_| " ENDOF
  ENDCASE ;
  
: Third_Line
  CASE
  0 OF ." |_| " ENDOF 1 OF ." | " ENDOF
  2 OF ." |_  " ENDOF 3 OF ." _| " ENDOF
  4 OF SPACE SPACE ." | " ENDOF 5 OF SPACE ." _| " ENDOF
  6 OF ." |_| "ENDOF 7 OF SPACE ." |  "  ENDOF 
  8 OF ." |_| " ENDOF 9 OF SPACE ." _| " ENDOF
  ENDCASE ;

: LED 
  SPLIT
  NPICK
  DEPTH 3 / 0 ?DO First_Line LOOP CR
  DEPTH 2 / 0 ?DO Second_Line LOOP CR
  DEPTH 0 ?DO Third_Line LOOP ;

And of course...you want to see an image...so here it goes -;)


Hope you like it... -:D

Greetings,

Blag.
Development Culture.

martes, 21 de julio de 2015

My first post on Forth

So...after a very long time...I finally decided to learn Forth...and if I thought I have dealt with difficult programming languages before...I was like Jon Snow...I knew nothing -:(

Forth is a stack based programming language...meaning that you program using a stack with the LIFO functionality...Last In - First Out...

Something like this...you enter 1 2 3 and Forth will output it as 3 2 1...weird, huh?

Of course...I started to read a book...and unlike most other times...I have finish it a long time ago...but with Forth...one book is not just enough...I have been reading and coding like crazy...

The book is Starting Forth by Leo Brodie...


The book itself is really good...it's 166 pages so it's not very long and gives you a nice introduction to the world of Forth...of course...as I said...one book is not enough...and even when this book is really good and highly recommended...Forth is very difficult to grasp but learning it is just amazing -:)

It took me a very long time but finally I was able to come with an example of my already "famous" Fibonacci Numbers...

Fibo.fth
: FIBO 
   1 SWAP 
   0 DUP . 
   ?DO 
      DUP . OVER OVER + ROT DROP 
   LOOP 
   DROP DEPTH 
   DEPTH 2 = IF 2DROP 0 THEN 
;

I told you...Forth is not by any chance and easy language...and actually I wrote the code in just one line...but put it here in different lines to make more clear...

Let's see an image...


I'm sure I going to spend quite more time with Forth...as I feel that's there so much to learn...if you like what you see...learn it too -;) Otherwise...look for something less weird -:)

BTW...I'm using pForth...I used gForth when I first started but I think pForth is more Forth complaint...

Greetings,

Blag.
Development Culture.