Sunday, September 21, 2008

Scheming flirtations

Trying to wrap my head around Schemes syntax, which is quite a different style of writing then I am used to.


An example at the childs level:

Scheme:
(define x 2)
(define y 5)

(if (> y x)
    (display y)
    (display x))

; which could also be written as if one wanted to use cond instead
(cond ((> y x) (display y)) ((< y x) (display x)))

C and related languages:
int x = 2;
int y = 5;

if (y > x) {
    printf("%d", y);
} else {
    printf("%d", x);
}

/* which could also be written on one line as */
if (y > x) printf("%d", y); else printf("%d", x);
I don't really have a problem with the parenthesesification, but the prefix notation :\. Let's just say, I've used infix notation since kindergarten, and internally my brain does too by now lol. Notational example
prefix + 2 2 --> 4
infix 2 + 2 --> 4
postfix 2 2 + --> 4


Getting my head to live with prefix notation, is the only thing that is pushing my luck, so far that is....


This is how I spend a night off work? I think I really need to get a better life again >_>

No comments:

Post a Comment