[plt-scheme] Why would the order of functions matter?

From: Jos Koot (jos.koot at telefonica.net)
Date: Thu Nov 20 09:25:39 EST 2008

----- Original Message ----- 
From: "Marco Morazan" <morazanm at gmail.com>
To: "plt edu" <plt-edu at list.cs.brown.edu>
Cc: "Scheme PLT" <plt-scheme at list.cs.brown.edu>
Sent: Thursday, November 20, 2008 2:52 PM
Subject: [plt-scheme] Why would the order of functions matter?


> Dear All,
>
> I have a student getting the following error:
>
> Welcome to DrScheme, version 4.1.1 [3m].
> Language: Beginning Student with List Abbreviations; memory limit: 128
> megabytes.
> reference to an identifier before its definition: 
> insert-everywhere-in-a-word
>>
>
> The questioned identifier is defined as a function after its first
> reference. When I re-arrange the function definitions DrScheme no
> longer complains. What can be causing this?

Exactly what the error message says, I think.

(define (foo x) (bar x)) ; ok, for the value of bar is not yet required 
(only its (top level) binding)
(define (bar x) (+ x 1)) ; ok, now variable `bar' has its value.
(foo 3) --> 4

However:
(define (foo x) (bar x))
(foo 3) --> reference to an identifier before its definition: bar  Variable 
`bar' has no value yet.
(define (bar x) (+ x 1))

Jos

>
> -- 
>
> Cheers,
>
> Marco
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme 



Posted on the users mailing list.