Wednesday, September 19, 2012

Crushing nuts with Squirrel!




"Squirrel is a high level imperative, object-oriented programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games."

Created by Alberto Demichelis, it is an imperative, functional, object-oriented and also a scripting language all in one. Though it's relatively young--making its debut last 2003--Squirrel already had its stable release last July 19, 2012. Squirrel 3.0.3 is now up for grabs in the net under MIT LicenseIt is highly influenced by programming languages like Python, Lua, JavaScript and C++ and uses a C-like syntax. It can be used for commercial and non-commercial products because it's free and open source.

(For further information about Demichelis, you may visit his site at http://www.demichelis.net/)

Why was Squirrel created in the first place?

According to the author of this programming language,
"I was working on a game using Lua as scripting language; while I'm in love with Lua's design I was having problems with the garbage collector. Initially, I tried to convert the Lua from garbage collected to referene counted, and then I decided to create a brand new language designed around my needs and vision of scripting. Later on, a colleague of mine suggested me to distribute it as open source."


Language Features:
  • dynamic typing
  • delegation
  • classes & inheritance
  • higher order functions
  • lexical scoping
  • generators
  • cooperative threads(coroutines) 
  • tail recursion
  • exception handling
  • automatic memory management (CPU bursts free; mixed approach ref counting/GC)
  • both compiler and virtual machine fit together in about 7k lines of C++ code and add only around 100kb-150kb the executable size.
  • optional 16bits characters strings
  • powerful embedding api
    • eg. function/classes can be defined by scripts or in C
    • eg. objects can fully exist in the VM or be bound to native code
    • eg. classes created in C can be extended by scripts or vice-versa 

Squirrel, just like in other PL uses the equal sign ( = ) for assigning a value to a variable. But it also has a special operator called the New Slot Operator ( <- ) which is a conjunction with tables to create a new slot before the assignment if the assignment references a non-existent slot identifier.

table.x <- y; // creates x if not present in table and assigns the value of y to x

  It also supports bitwise operators such as:

    • Bitwise AND (&): a & b
    • Bitwise OR (|): a | b
    • Bitwise XOR (^): a ^ b
    • Bitwise NOT (~): ~a
    • Left shift (<<): a << b
    • Right shift (>>): a >> b
    • Zero-fill right shift (>>>): a >>> b

  Bitwise operators only work on integers, any other type will
  cause an exception.

  Its statements as well as operators and how it is executed are very much alike as C with a touch of Java. This is evident with its loop statements and its exception handling.

Here are some sample codes we tried ourselves:

    Since Squirrel had been recently introduced and is being used mostly for game development, we had a hard time looking for an application where we can run it. The following code snapshots are done with the use of the Squirrel Shell (which can be downloaded from http://sourceforge.net/projects/squirrelsh/). 

Here is a simple hello world program:




    The printl() function prints the string inside it then prints a new line. You can use the print() instead if you do not want to print a new line after the string.


    Our second example is a simple scanning of the user's input:




 Here, we use the function scan where the console will wait for your input until you press the enter key. The value it gets is initially a string so if you want to have an input that is an integer, you need to convert it using the function tointeger() as illustrated in our next example.



   The tointeger() function is used like how methods are used in Java.


Did you know that...


  • Squirrel was used as a scripting language in games like Left For Dead 2 and Final Fantasy Crystal Chronicles: My Life as a King, Portal 2 and Alien Swarm?
  • It already influenced a programming language named MiniD?


Insights...


"This is the first time I've heard this programming language. And all I could say about this PL is that it is very much like C but with added features of Java or Python. For programmers who really want to try a nice hybrid of an imperative and object-oriented--with scripting as a bonus-- I think they would find this PL a very nice language to learn. And for a newbie language like this, I think it is very promising because the development is centralized and considering that an application like Left for Dead 2 used this as a scripting language already tells us a lot. Lastly, I really find the file extension (.nut) of this PL very amusing and witty. :)"


- Reneelou "Renz" Estacio


"The syntax is almost alike to JAVA and C++, making it easier to understand and code. But the downfall is that, its SO HARD to find its compiler as well as sample codes due to the fact, as said earlier that its a new programming language. Still its cute, living up to its name, SQUIRREL. :))))" 
 -Sefora Doreen Galos (2010-42177)
"Squirrel is a language that can be easily understood because of the fact that it is inspired by popular languages such as C/C++ and Java. Its syntax is very similar to the said languages which makes it easier for programmers to use. Also, it is a multi-paradigm language. It is imperative, which ensures us its performance; functional, which tells us that it is reliable; and object-oriented to make representations of real-world problems much easier. And since it is lightweight, it is very good for development of games in the net or even on IOS and Android OS. If only the resources (and tutorials) would increase, then I think squirrel might become very popular language game development."
-Kristine Bernadette Pelaez (2010-16170)
"I find squirrel very easy to understand because of its similarity to C and Java in terms of its syntax, It's like programming in an object-oriented way in C syntax. In terms of learning the language, it is easy to use squirrel but I guess, it has still a long way to go since it is still a new PL. "
-Anna Rodina Marte (2010-01064)




Sources:
http://www.squirrel-lang.org/
http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/FAQ.html
http://en.wikipedia.org/wiki/Squirrel_(programming_language)



Members: (T-5L)

Estacio, Reneelou Marie D.
Galos, Sefora Doreen R. (2010-42177)
Marte, Anna Rodina S. (2010-01064)
Pelaez, Kristine Bernadette P. (2010-16170)

No comments:

Post a Comment