[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ghil repl

From: Andy Wingo
Subject: ghil repl
Date: Wed, 12 Nov 2008 00:29:58 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

A brief note:

Piqued by the need to document GHIL, I noticed a lack of Replage (noun,
"in the state of repl") in the GHIL language. No more!

    scheme@(guile-user)> ,language ghil
    Guile High Intermediate Language (GHIL) interpreter 0.3 on Guile 1.9.0
    Copyright (C) 2001-2008 Free Software Foundation, Inc.

    Enter `,help' for help.
    ghil@(guile-user)> "foo"
    $1 = "foo"

Ooooh! ghil@ means that the input language is GHIL, or rather, the
external representation of GHIL in S-expressions. Self-quoting values
translate into <ghil-quote> instances, which, when compiled and
executed, evaluate to results: above, "foo".

    ghil@(guile-user)> (values 1 2 '(3 4))
    $2 = 1
    $3 = 2
    $4 = (3 4)

But self-quoting values are a degenerate case. Besides bare symbols,
which translate into <ghil-ref> instances, the external representation
of GHIL is a tagged list, whose interpretation depends on the tag. In
this case, `values' corresponds to <ghil-values>, which ends up
returning multiple values.

    ghil@(guile-user)> (values* 1 2 '(3 4))
    $5 = 1
    $6 = 2
    $7 = 3
    $8 = 4

Here we see values* -- used by the scheme compiler in the (apply values
...) idiom.

    ghil@(guile-user)> (lambda (x) #f () (call * x x))
    $9 = #<program #(3 18 #f) (x)>

The form of the `lambda' GHIL construct is not the same as scheme's
lambda, though they are functionally equivalent. Its form goes like this:

   (lambda ARGS REST? META . BODY)

Here the args are (), there are no rest arguments, and no
meta-information. The body is a call expression:

   (call PROC . ARGS)

Here we call `*' with x and x.

    ghil@(guile-user)> (call $9 5)
    $10 = 25

Incidentally, $9 is a <ghil-ref> instance.

    ghil@(guile-user)> (call (lambda (a b) #f () (inline add a b)) 10 20)
    $11 = 30

An illustration of procedural values and <ghil-inline>.

The whole range of forms understood as external representations of GHIL
will be documented, but for now it may be seen in parse-ghil in
module/system/il/ghil.scm. The tags are:

    quote void lambda begin bind bindrec set! define if and or mv-bind
    call mv-call inline values values* compile-time-environment

Happy hacking!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]