27 October 2009

Metro Skyline

This a photo that I took on the 31st floor of a building in Makati. The view is already going outside Makati CBD but not bad at all. I wasn’t able to bring my tripod so I had to mount it somewhere. If you saw my position while taking these shots you will really think that I will be committing suicide.

(click image to view full size)

Bookmark and Share

My Sanctuary

I’ve been a nomad in my new job lately. I’ve been transferred to different workplaces from time to time. All of them had their pros and cons. But the most recent workplace is prolly the best that I have. Aside from the fact that I am already with my team (since we’re in the same prison already), the view is by far the best of the best.

This is a view of the Manila Bay from my workstation when the sun is about to set:

sunset

(300mm, f/10, ISO-200, 1/125sec)

~oOo~ ٩(̾●̮̮̃̾•̃̾)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃ -̃)۶ ~oOo~

Patience.. Patience.. and more Patience.. I was waiting for the right timing when the sun was about to set in the horizon but to my dismay the clouds just ruined everything. So here’s a photo of the sun while it was still high:

sunset

(300mm, f/8, ISO-200, 1/125sec)

~oOo~ ٩(̾●̮̮̃̾•̃̾)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃ -̃)۶ ~oOo~

For the meantime, I’m still using my personal laptop since the service unit is so Jurassic that it can’t run the applications that I needed. The only purpose I’m using two laptops is that the personal one is used for development/learning whilst the other one is for research via the internet (and playing Yakuza wars on FB hehe ):

workstations

Workplace

~oOo~ ٩(̾●̮̮̃̾•̃̾)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃ -̃)۶ ~oOo~

The photo below is a snapshot of how an Erlang source code looks like. I’ll be posting more on Erlang once I’ve been able to convert all my exercises and machine problems written in Lisp into Erlang.

Erlang Snapshot

~oOo~ ٩(̾●̮̮̃̾•̃̾)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃ -̃)۶ ~oOo~

All photos were posted as is. No postprocessing was done and all photos are copyrighted by me. Should you wish to have it, just ping me a message and don’t forget to link back to my site. Thank you!

- end -

Bookmark and Share
14 October 2009

Learning Lisp

I’m finally done with the basics of Lisp. But being able to finally understand how to use Lisp does not end there. It simply means that there will be more interesting problems to solve in the future and expectations will be high. For this entry, I will be discussing a few things about what I’ve learned about Lisp. I will also be posting source codes from the exercises that I answered and likewise the real-world implementations that I created using Lisp.

I’ve read almost a third of Paul Graham’s On Lisp Book and allow me to summarize it, based on my own pace and understanding, in a nutshell. I will only write important pointers that you might help you understand lisp better. The discussion on the syntax will already be up to you. Don’t worry though since I’ll be posting materials for your reference. :)

Introduction:
Lisp stands for List Processor and was developed by John McCarthy in the late 1950s. The paradigm it follows is Functional Programming. That is, functions are the natural place to begin with. This type of paradigm tells you what it wants to do rather than what to do. Lisp allows you to change the language to suit the solution to the problem. Prototyping and debugging of programs are easier and more interactive. Arguments are also evaluated first before the function is issued since it follows the read, evaluate, and then print cycle. Lastly, Lisp can either be compiled, interpreted, or both. Examples of software created using Lisp are GNU Emacs, Autocad, and Interleaf.

There are a lot of dialects that you can use to program in Lisp. The most popular dialect is Common Lisp. But for the entirety of my Lisp entries, I shall be dealing with Common Lisp syntax unless otherwise stated. For the interpreters that you can use , refer to my previous entry which discusses on how to install the interpreters.

In Lisp, f(x) is written as (f x) since it is Postfix.

eg. cos(0) is written as (cos 0).

In Lisp, there are only 2 kinds of objects:

1. Atoms – symbols, arrays, and other data structures.

* symbols are represented as sequences of characters of reasonable length.

2. Lists – are recursively constructed from atoms. It may contain either atoms or lists, or both.

* “()” or “NIL” is both an atom and a list.
* special atoms: numbers, t, or nil.
* primitive functions: +, -, *, /, exp, expt, log, sqrt, sin, cos, tan, max, min.

Ingredients of an abstract data type:

1. Constructors – forms that create new instances of a data type.

i. cons – allows you to add a member to the front of a list

eg. (cons ‘a ‘(1 2 3)) -> (A 1 2 3)

ii. quote or ‘ – use if you do not wish the interpreter to evaluate.

eg. (setq a 4) = (set ‘a 4) = (set (quote a) 4)

*shorthand commands are called macros.

2. Selectors – returns one of its components, given a composite object out of several components.

i. first or car

eg. (first ‘(1 2 3)) -> 1

ii. rest or cdr

eg. (rest ‘(1 2 3)) -> (2 3)

3. Recognizers – expressions that test how an object is constructed.

Lists versus Sets:
1. Sets are unordered but lists are.

eg. (a b c) and (c b a) are two different lists.

2. An element either belongs to a set or not. There is no notion of multiple occurences. Yet, a list may
contain multiple occurences of the same element.

eg. (a b b c) is a list whilst (a b c) is a set.

Recursions:
1. Linear Recursion – the function may make at most one recursive call from any level of invocation.

eg. factorial.lisp

2. Multiple Recursion – the function definition contains two or more self references.

eg. fibonacci.lisp

3. Structural Recursion – the function checks the structure of the parameter.

eg. recursive-list-length.lisp

Tail Recursion means that when the result of each recursive call is returned right away as the value of the function.

* when implementing linearly recursive functions, you are encouraged to restructure it as a tail recursion after you have fully debugged your implementation.

The implementation of tail recursion is new to me since I don’t(or did not) really bother using this in the 2 years that I’ve been working as a developer. This may have been introduced in my Computer Science classes but was not really given that much attention. So I didn’t bother.

Iterators:

- in higher-order function, mapcar is used and does exactly what mapfirst is intended for.

- *car is used to define first in other dialects and rest was called *cdr in these dialects.

- Common Lisp still supports car and cdr but stick with the more readable first and rest.

Types of Iterators:

1. Generic Iterators – captures the generic logic of iterating through a list.

2. Transformation Iterators – transforming a list by systematically applying a list member that
satisfies a given condition.

eg. repeat-transformation.lisp

3. Filter Iteration – screening out all members that does not satisfy a given condition.

eg. remove-short-lists.lisp

Compiling to executable:

Also, if you want your program to be executable within the commandline, you can issue this command:

(save-lisp-and-die “<executable_file_name>” :toplevel #’<function_name> :executable T)

eg. (save-lisp-and-die “javaphones” :toplevel #’main :executable T)

*please do note that I’m running on Ubuntu 9.04 and I haven’t tested it on other Linux distros.

So far those are the pointers written in my Rutter(Blue Notebook). You can download the resources via torrent or direct download (6.73MB). Also, you can join the mailing list at comp.lang.list. There’s a lot of spam there but there a few, great people who can help you in your Lisp endeavors.

Enjoy! :)

“But no one can read the program without understanding all your new utilities.”

Bookmark and Share