Kristian Lunde

www.klunde.net

Archive for the ‘Misc’ Category

Hello Standard ML (of New Jersey)

with 4 comments

Back when I was at the university we had a course called “Programming languages”, there we learned a little something about a lot of known and less known programming languages. One of these languages was Standard ML, and I remember that I was quite fascinated with that language, it was so different from everything else we had learned. Since then the functional languages have become a bit more common, with Erlang, F#, Clojure, Scala and Haskell as some examples (more functional languages can be found here: http://en.wikipedia.org/wiki/Category:Functional_languages). I have not used any functional languages since then and I thought I would just briefly refresh my memory by installing Standard ML and try the most basics of the language.

Installation

I am currently using a Mac so installing sml-nj was really simple. I downloaded the mac .dmg package from http://www.smlnj.org/ and ran the installer. the system was installed by default at /usr/local/smlnj-110.68. I added the path to my .profile file, which enables me to start sml without being in the sml bin root folder.

When that was done I could start the sml shell (just type sml in your shell):

  1. kristian-lundes-macbook-pro:sml kristianlunde$ sml
  2. Standard ML of New Jersey v110.68 [built: Thu Sep  4 16:23:20 2008]

Example 1: Start standard ML

(To exit the sml shell use key combination: CTRL + D).

First touch – Hello World

I always do a Hello World programming in a new language. Even though I have been playing around with Standard ML before I do not remember a hole lot of it, so I start from scratch.

  1. - "Hello World";
  2. val it = "Hello World" : string

Example 2: Print “Hello World”

The – is the sml prompt, to end a expression the semi-colon is used. So to write Hello World all you have to do is to apply quotes around the text and end it with ; and hit enter. The result gives us the text and the data type.

The first function

To do a Hello world proved to be quite simple, so lets take it a bit further and write a function which prints the hello world text.

  1. 1. – fun hello ():string = "Hello World";
  2. 2. val hello = fn : unit -> string
  3. 3. – hello();
  4. 4. val it = "Hello World" : string

Example 3: The first function

The function itself is a one liner seen on line 1 in the example above. The function is created using the fun keyword, the function is named hello and have no parameters which result in the (). The function return a result of the data type string, this is defined with the :string element, The content of the function start after the equal sign, and is just a print of the hello world text. To end the function close semi-colon.

When creating a function which is compiled we get the response seen in line 2. This tell us that hello is a function and that it return a string. I believe the unit text mean that the function does not take any parameters (I might be wrong).

To execute the function just type the name of the function, see line 3 in the example above, this result in printing out the “hello world” text as seen in line 4. Line 4 tell us that the result of the function is “Hello World” and the data type is a string.

Functions with parameters

Now we have created our first function, but a function usually need one or more parameters, so let us have a look at that. The next function is a simple echo function which just print the text to screen.

  1. 1. – fun echo (s:string):string = s;
  2. 2. val echo = fn : string -> string
  3. 3. – echo("Hello World");
  4. 4. val it = "Hello World" : string

Example 4: Function with parameter

Line 1 in example 4 define the function, it takes one parameter s as a string, the return data type is also a string and it just output the string to the shell. When the function is executed in line 3 the parameter is “Hello World” and the result is seen in line 4.

To add more than one parameter just add a comma between the parameters. Remember to define a data type on all the parameters.

Example 5 is a function which takes to parameters and sum the two parameters together before returning the result.

  1. 1. – fun sum(x:int,y:int):int = x + y;
  2. 2. val sum = fn : int * int -> int
  3. 3. – sum(10,20);
  4. 4. val it = 30 : int

Example 5: function with multiple parameters

Lambda expressions

Lambda expressions is also known as anonymous functions, and create a function without any name. This is used quite frequently in sml and are written as seen in example 6.

  1. fn() => print "Hello World";

Example 6: lambda expression.

The example 6 do not do much except print out the Hello world text when it is called. Naturally a lambda expression must be called as part of another function or code snippet.

Load a function from file

To load sml code from a file just use:

  1. - use "../sml/myfile.sml";

Where you replace ../sml/myfile.sml to point to your file.

Resources

This is the best online introductions I have found so far are:
www.pllab.riec.tohoku.ac.jp/smlsharp/smlIntroSlides.pdf
http://www.cs.cornell.edu/riccardo/prog-smlnj/notes-011001.pdf

A short FAQ:
http://www.smlnj.org//doc/FAQ/index.html

I really have not showed anything of the fancy stuff you could go about and build with Standard ML, but hopefully I am able to spend some more hours playing around with standard ML and write another blog post.

Written by Kristian Lunde

December 17th, 2008 at 12:52 am

Posted in Misc,Programming

Tagged with ,

The number is 4

with 3 comments

I got a challenge from Ramona tonight where I should answer a few questions.

1. Name 4 jobs I have had:

  • Senior developer @ Derdubor AS
  • Software engineer @ Teleplan AS
  • Salesman @ Blok Computer Services
  • Assisting nurse @ Sarpsborg psychiatric center

2. 4 movies I could watch again:

  • Fabuleux destin d’Amélie Poulain, Le
  • Lock, stock and two smoking barrels
  • Pulp Fiction
  • In China they eat dogs

3. Name 4 places I have lived:

  • Halden
  • Oslo
  • Sarpsborg

4. Name four tv shows I like:

  • The king of Queens
  • Two and a half men
  • Friends
  • Seinfeld

5. Four places I have been on vacation:

  • Alfas Del Pi (Spain)
  • Karlstad (Sweden)
  • Aalborg (Denmark)
  • Bournemouth (UK)

6. Four web sites I visit every day:

  • Google Reader
  • Google Analytics
  • Facebook
  • Twitter

I pass this on to Mats and Jan Petter and everyone else that feels like answering these questions.

Written by Kristian Lunde

November 8th, 2008 at 10:58 pm

Posted in Misc

My car is for sale

without comments

Since I am moving to the UK, I do not need a car in Norway anymore, and I am therefore selling my car.

See the full ad in finn.no (in Norwegian):

http://www.finn.no/finn/car/object?finnkode=15172038

Written by Kristian Lunde

October 16th, 2008 at 11:29 pm

Posted in Misc,Real Life

Jobs I would like to try out

with 2 comments

Have you ever wondered how it would be like to have a completely different line of work than your acctual work?
I have had this thought a few times and I’ve come up with a list of jobs I find interesting, some of them are not realistic at all since it requires years of studies and work experience, but I still choose to mention them. Other jobs would probably only be interesting in a week or so. The jobs are randomly listed and not listed by most wanted :P

Okay here we go:

  • Crosswords author (sounds interesting enough, but just for a week or so).
  • Helicopter pilot (requires years of studies and flight experience)
  • Architect
  • Work at a local recycling factory (only for a week, just to see what they actually do there)
  • Athlete (but I guess that don’t count as a line of work)
  • Carpenter
  • Professional photographer
  • Car designer
  • Chef (I really like cooking)
  • Millionaire :P

Please add a comment if you have a list of jobs you’d like to try out.

Written by Kristian Lunde

October 6th, 2008 at 4:07 pm

Posted in Misc,Real Life

Orange Bus wallpaper

without comments

Orange bus wallpaper

Torunn in Orange Bus submitted a wallpaper for Smashing Magazines October wallpaper download, and it got in :) Congratulations Torunn and Orange Bus, and good work Torunn :)

Guess what wallpaper I’ve got on my computer this month? :P

Written by Kristian Lunde

October 4th, 2008 at 1:06 pm

Posted in Misc,web design

Tagged with

123-meming

without comments

Mats forwarded the 123-meme to me today, I’m not entirely sure what 123-meming really is but the instructions are:

  1. Pick up the book closest to you
  2. Open page 123
  3. Find the 5th sentence…
  4. …and publish the next three sentences
  5. Link to 5 other bloggers and tell who linked you

The book closest to me is: AGILE PROJECT MANAGEMENT WITH SCRUM, on page 123, sentenc nr 5 is:

During this day, the nonfunctional scaling requirements for this particular project are determined and placed in the Product Backlog. For example, if you are scaling the project to use multiple teams, the following nonfunctional requirements should be added to the Product Backlog:

  • Decompose business architecture to support clean-interface multi-team development.
  • Decompose system architecture to support clean-interface multi-team development.
  • If necessary, define and implement a development environment to support multi-team collocated or distributed environments.

I pass this 123-meme on to Erik.

Written by Kristian Lunde

May 23rd, 2008 at 8:13 am

Posted in Misc

Cheat sheets

without comments

When talking about cheat sheets, www.ilovejackdaniels.com has a list of a few good cheat sheets. I’ve actually printed some of them at work and taped them to the wall next to my computer.

Thanks to Dave Child for doing the work of putting together these sheets.

URL: http://www.ilovejackdaniels.com/cheat-sheets/

Written by Kristian Lunde

May 12th, 2008 at 9:19 pm

Posted in Databases,Misc,PHP,web development

Tagged with , , ,

klunde.net redesigned

without comments

Tonight I did a quick google search for a new wordpress design for klunde.net, I came over this page where I downloaded the earthtones design and added it to www.klunde.net

Written by Kristian Lunde

May 11th, 2008 at 9:23 pm

Posted in Misc,web design

Tagged with ,

Patterns for PHP

without comments

I came over this useful site: http://www.patternsforphp.com while browsing through the phpplanet rss. It has a introduction to the most common patterns, and its all written in PHP, quite handy when you need to look up a pattern.

Written by Kristian Lunde

April 30th, 2008 at 3:16 pm

Posted in Misc

Tagged with

Yet another wordpress user

without comments

Okay, I finally realized that I’d be better of using an existing blog publisher than writing the code myself. So far I’ve written most of the code on www.klunde.net, I tried out Joomla a few years ago, but I wasn’t quite happy with it, so the old php code I wrote in 2003 has done its purpose. Well I’ve started up writing my own CMS and web applications a few times now, and I have to admit I have a lot of fun writing these small web applications, but at the moment I just doesn’t have the time to maintain and write my own web application.

So bye bye old www.klunde.net and welcome to wordpress @ klunde.net. At the time of writing I’ve been using wordpress for approx. 20minutes, and I must say I’m impressed, easy administration interface, and easily set up :D

Written by Kristian Lunde

April 18th, 2008 at 9:39 pm

Posted in Misc

Get Adobe Flash player