[racket] Fundamentals

From: synx (plt at synx.us.to)
Date: Wed Oct 13 22:06:46 EDT 2010

Hash: SHA1

On 10/13/2010 05:36 PM, Mathew Kurian wrote:

> Racket as a language built on top of another base language (i.e.
> Assembly or C)

No, racket is not built on top of another base language.

> or is it directly connected to the processor language?

The language racket does not directly translate to the processor
'language'. The racket program reads that language in, and based on what
it reads, sends a sequence of instructions to one, or more processors.
These sequences are optimized "in time" so that they will only always
work at the time they are executed, so you couldn't save them to a file
and replay them 10 minutes later, hoping the computer would do the same

The following example for instance:

(module example racket/base

  (let sum ((i (random 5)))
    (if (<= i 0) 0
        (+ i (sum (- i 1))))))

The assembly language directives racket might produce when evaluating
that program could be as follows: first it produces the assembly needed
to get a random number between 0 and 5. Then it produces the assembly to
add 1 and 0 (the innermost recursion), then 2 and 1, then 3 and 2, then
5 and 4. Then it produces the assembly to print out the number 9. The
racket program can and will analyze such loops, and unroll them so that
the assembler never sees a single jump instruction, even if the amount
of times the loop is executed is only determined the moment of the
code's evaluation. Or maybe it won't. But the point is that if you saved
the instructions it produced, that is

< random number 0 to 5 ... >
< add 1 and 0 >
< add 2 and 1 >
< add 3 and 2 >
< add 4 and 5 >
< display 9 to stdout >

And then you blindly executed those instructions again, it would
calculate that random number, then ignore it, add up 0 to 4, then ignore
that result, then display 9 to standard output every time. But if you
ran racket on that program again, it would produce varying amounts of
"add" instructions, and in fact sometimes it would provide a single add
instruction followed by a jump-if-zero loop, if the amount of iterations
is deemed too high by the optimizing compiler to unroll.

You can convert racket to a byte code format (using raco make) but
that's as far as you can go before the resulting programs may change
unpredictably between two executions of the same code. Any further and
you will most certainly lose vital state information, like trying to
optimize the construction of your roller coaster by removing the track.
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


Posted on the users mailing list.