lunes, 13 de octubre de 2014

My first post on Racket

In my eternal quest for weird programming languages...I came out finding Racket...which is basically the new name of "PLT-Scheme"...from the Lisp family...


Racket can be installed on Windows, Mac and Linux...so it's pretty cool -:) And also comes with a nice IDE called DrRacket...


I gotta say...Racket is like nothing I have ever seen before...that's why I love it -:D

And here comes the most weird thing of all...Racket is...
  • Functional
  • Procedural
  • Modular
  • Object-Oriented
  • Logical
  • Reflective
  • Meta

Crazy, huh? Right now I'm reading an awesome book called "Realm of Racket"...


And after reading the first 61 pages (yep...no more) I was able to translate my Fibonacci Haskell app into Racket...so here goes the code...

Fibonacci.rkt
#lang racket
(define (showFib num)
  (fib num 0 1))

(define (fib num a b)
  ( cond [(and (> a 0) (> num 1)) (append (cons (+ a b) '()) (fib (sub1 num) (+ a b) a))]
         [(= a 0) (append (append (cons a (cons b '())) (cons (+ a b) '())) (fib(sub1 num)(+ a b) b))]
         [(= 1 num) (append '())]))


Now...if we run it...we're going to see this...


Cool, huh? Works just as expected -:) Couldn't be happier -;)

Greetings,

Blag.
Development Culture.

No hay comentarios: