views:

55

answers:

1

We've been taught various syntax and told how to write definitions, but we've never written any code an ran it. What is the order that Scheme code runs in?

Thanks!

+3  A: 

The question is a bit vague, but if you're asking about which evaluation strategy scheme uses:

Scheme uses applicative order evaluation.

Edit: Ok, that wasn't what you were asking. So here is the answer to your question as I understand it now:

Scheme code is executed top-to-bottom: I.e. the first expression in the file is executed first, then the one beloew that, then the one below that and so one until the end of file is reached.

So if you have a file containing:

(display "hello ")
(display "world\n")

Then (display "hello ") is executed first and then (display "world\n").

sepp2k
Thank you very much, I cannot believe we have not been taught this!
Alex
@Alex: Since you'll probably run most of your code from the REPL instead of creating runnable programs, knowing how to create runnable programs isn't really as essential as in other languages.
sepp2k
For the record, MOST scripting languages are run top-to-bottom, since they don't have specific entry points like "main", but in many languages, function definitions are allowed to occur anywhere.
erjiang