QWANtify is excited to announce, effective May 1, 2010, their purchase by Safe Bridge Solutions, Inc. of Madison, WI. Read More »

Newsroom

Entries Tagged: Languages

The Latest New/Old Language: Erlang

I was poking around the interweb for some interesting technical books to purchase.  I decided to head on over to the Pragmatic Programmers website because I’ve purchased their books in the past and have, in general, been quite happy with the books they put out.  One of the most recent books they’ve released is called “Programming Erlang: Software for a Concurrent World” (http://www.pragmaticprogrammer.com/titles/jaerlang/index.html).  I was intrigued, so I bought the book.

It came in the mail the other day and I started to read it.  I’m not that far into it, but a few things really strike me about the language.

  • It’s been around for awhile.  The Wikipedia entry (http://en.wikipedia.org/wiki/Erlang_%28programming_language%29) indicates that it first appeared in 1987 and was created at Ericsson, the cell phone company.
  • It’s designed for concurrent, highly parallel, and fault-tolerant systems.
  • Syntactically, it feels somewhat like Ruby and Scheme (or Lisp).
  • It’s a functional language.  It feels more purely functional than Ruby does.
  • Arbitrary length integers.  Ahh… finally, no need to worry about overflows!
  • Variables are single-assignment.  You cannot change the value of a “variable” once it has been assigned a value.
  • The equals operator (=) is NOT an assignment operator.  It’s a pattern matching operator.  But, when used with a variable that has not been assigned a value, the value gets assigned.  This one got a “Whoa” (insert Keanu Reeves here) from me.

I really think that I’m starting to enjoy dynamically typed, functional languages.  It’s quite a departure from standard object-oriented imperative programming.  It’s really interesting to not have to deal with objects all the time and to work with the elegance that functional programming brings to the table.

The little devil on my shoulder that likes to keep me programming in Java keeps asking me “But what is it good for?” to every new and old language that I encounter.  It’s a question that I like to keep in mind when evaluating different languages.

I can’t answer that question about Erlang yet.  I’m not that far into the book.  But, it’s definitely an interesting language.

Filed in: Team Member Blog Comments (0)languages

Hello World

Because I like to do strange things sometimes I thought it would be fun to start a Hello World archive.  As I get interested in checking out other languages, writing a Hello World program is the first and easiest thing to program.  I figured that archiving all the programs would be a nice thing to do as a point of reference.

I may expand the archive to include more advanced programs for comparison, but for now Hello World is a good start.

Feel free to check it out at http://tech.fradkin.com/helloworld/index.html.

Filed in: Team Member Blog Comments (0)languages

Factorial Fun

I just got back from Narglethorpe; at least I’m pretty sure it wasn’t a dream. One of the most spectacular animals on the island is called “The Beast of Narglethorpe” or TBON. Now, local legend has it that TBON has some interesting properties. If a person were to come upon this ferocious beast and call out a number, the beast will undergo a miraculous transformation in which it splits up into numerous other (albeit smaller) TBONs based on the number called out. Facing the possibility of being eaten by the beast, I decided that there was scientific merit in trying to verify the legend. So, armed with a machete, some camouflage, and a camera, I wandered into the jungles of Narglethorpe. The foliage was so dense that it was quite dark, but this did not deter me in the slightest. I went further and further into the jungle hoping to catch a glimmer of this monster. After a bit I heard a noise to my left. I turned, but saw nothing. I went on. Soon, I came to a clearing. I got to the middle of the clearing when I felt as if I were being watched. I turned around slowly and I saw that most amazing sight Ii had ever seen! Before me was the magnificent TBON!

Ten feet tall! Giant floppy ears! A cute puffball of a tail!

Terror inched across my body. I was paralyzed with fear. Until I remembered… “One!”, I managed to blurt out. Nothing happened. I thought for sure I was a goner. “Two!”, I shouted. The fearsome TBON split into two identical TBONs before my eyes. Identical beings, but each half the size of the original. Within a few seconds the two turned back into one.

Its eyes gleamed with hunger. Not undaunted, I cried, “Three!”. This time six smaller copies sprang forth. I was beginning to have an inkling as to what was going on. After some time, but longer than before, the six turned back into one. I quickly called out “Four!” Lo and behold, 24 copies appeared. I was quite excited and was ready to make things interesting. I quickly wrote down the following:

public class Factorial {
    public static void main(String[] args) {
        System.out.println(fact(new Integer(args[0]).intValue());
     }

    public static int fact(int factnum) {
        switch(factnum) {
            case 0:
                return 1;

            default:
                return factnum * fact(factnum " 1);
        }
    }
 }

Nice and easy recursion. Something about this seems a bit pedestrian, however. What if we tried this a different way?

if ARGV[0].to_i == 0
  puts "1"
 else
  puts((1..ARGV[0].to_i).inject(1) {|total, num| total * num})
 end

Nice and concise.

Another just for kicks:

(begin
  (define fact
    (lambda (n)
      (if (= n 0)
        1<br>
      (* n (fact (- n 1))))))
 (display (fact (string-&gt;number (vector-ref argv 0))))
 (newline))

Ahh… Very helpful. Three different ways to calculate a factorial in three different languages.

I figured that I didn’t have to go past the number five. Any more than that and I would not be able to see the TBONs that split. So I called out “Five!”. As the TBON split into 120 identical (much) smaller TBONs, I broke out into a huge grin. I thought, “This TBON isn’t too scary.” I pet a couple of the TBON clones. After a few minutes, the TBON reassembled itself into the regular, giant TBON. It glared at me again. I became afraid once more.

“Hey!”, said a voice behind me. I did a little jump and turned around slowly. A man stood behind me.

“He really won’t hurt you, you know.”, the man said.

“Oh, really?”, I answered. “He looks quite angry to me.”

“Nah, he’s harmless. I’ve lived here all my life and the Beast has never harmed a soul. He’s looking at you like that because of what you’ve got in your pocket.”

“My pocket?” Oh, how embarrassed I was.

I grinned again, reached into my pocket and pulled out the carrot and tossed to the TBON. The TBON caught the carrot, wiggled its nose, then bounced off back into the jungle. I turned around said thanks to the local and decided it was time to head home.

Authors note: The code samples in this post are all executable. The first is in Java, the second is in Ruby, and the third is in Scheme. They are setup to take a command line argument of the factorial to compute. Save the Java example to a file called factorial.java, compile it using "javac factorial.java" and execute it using "java Factorial n" where 'n' is the factorial to compute. Save the Ruby example to a file and run it using "ruby file.rb n". The Scheme example should be saved to a file and run using (I use MzScheme) "mzscheme -r file.scm n".

Filed in: Team Member Blog Comments (0)languages

Scheming on a Thing

I’ve decided that I really need to be more multilingual. Not in the sense that I should speak another verbal language, though that would be a really great idea, but in the programming language sense.

All of the languages that I’ve learned in the past are standard procedural, object-oriented languages. There is a whole other realm of languages which I hadn’t really taken a look at before, functional programming languages. That’s one of the things that really stands out about Ruby. Ruby has a wide range of uses, but the most noticeable thing about it is that even though you can use it as an object-oriented language, it contains a lot of functional programming paradigms.

Functional programming is a bit strange to wrap your head around if you’ve never really used it before. The entire structure is based upon Lambda Calculus which seems to be nearly impossible to understand unless you’ve got a degree in mathematics. Lambda Calculus basically says that you can represent everything as a function that takes one argument and that argument can be another function. There are ways to represent the natural numbers, standard arithmetic, and even logic functions via Lambda Calculus. It’s pretty heady material to read.

I got curious and started taking a look at Scheme. Scheme is a derivative of Lisp, which makes it one of the “parentheses” languages. Lots and lots of them. It’s no worse than having curly braces everywhere, really. Functions are first class objects. It uses stack notation to perform arithmetic, so there is no operator precedence. It’s a really interesting language. I haven’t really used it for anything yet. I’m still looking through the language specs trying to figure out everything it can do. I’m sure I’ll have more things to say about it in the future. Until then, I’m just going to have some fun with it.

Filed in: Team Member Blog Comments (1)languages

Page 1 of 1 pages