> Next Robot Control Software
< Previous #f

4.3.1.1 Variables, or not

Global variables can be created with ‘define’. Local variables are created with ‘let’. Any variable’s value can be changed with ‘set!’. However, these facilities are rarely used (compared to other programming languages) in Guile.

Where most languages use variables to hold intermediate values in calculations, in Guile it is usual to perform intermediate computations in the place that you require the answer, i.e. do everything ‘on the hoof’.

Consider the following.

      (begin
         (define a 5)
         (let ((b 3) (c 4))
              (set! a (+ b c)))
         (display a))
      (display (+ 3 4))

It is a bit pathological, but indicates the efficiency of computing values in place (as in the latter example), rather than creating storage and putting computed values into the store area (as in the former example).

Note how ‘define’ is used to create a global symbol ‘a’, and ‘let’ is used to create two local symbols ‘b’ and ‘c’. Note also how ‘let’ in this case acts a little different to the let in Section xx (the latter is referred to as named-let, as it binds its own body to a named symbol given as first argument).

> Next Robot Control Software
< Previous #f
Copyright © 2010, 2012 DM Bespoke Computer Solutions Ltd
All rights reserved