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

From: Jos Koot (jos.koot at telefonica.net)
Date: Thu Nov 20 14:11:54 EST 2008

Ok that's a clearer question.

Pro your suggestion:
A student can program top down and  include tests immediately after each 
definition.

Contra your suggestion:
Why develop a habit that will not work in non-teaching-languages?

I don't know the starting level of your students nor the precise goals of 
your course, but if possible I would prefer to make the following 
distinction right from the beginning: between collecting the value of a 
variable and a (possibly forward) reference to a binding without needing the 
value yet. There would also a difference between a complete program in the 
definitions window and definitions entered in the interactions window, a 
difference that might disturb the student. Even without allowing side 
effects (read set!), the student should be made aware of the evaluation 
process. Mho.
Jos

----- 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 3:20 PM
Subject: [plt-scheme] Re: Why would the order of functions matter?


> Here's little more of the puzzle after some more investigating:
>
> Student's file:
>
> <some previous code>
> ...
> ;;; insert-everywhere/in-all-words: symbol a-low -> low
> ;;; to insert a symbol (s) between all letters and at the beginning
> ;;; and the end of all words of a-low
> (define (insert-everywhere/in-all-words s a-low)
> ;;; (s) is a symbol representing the letter to be inserted in a-low
> ;;; (empty? a-low) is true if a-low is empty
> ;;; otherwise,
> ;;; (cons? a-low) is true if a-low is a cons
> ;;; (first a-low) is the first word in a-low
> ;;; (rest a-low) is the list containing the a-low without (first a-low)
> ;;; (insert-everywhere/in-all-words s (rest a-low)) is the low
> ;;; with s inserted in (rest a-low) according to the contract
>  (cond
>    [(empty? a-low) (list s empty)]
>    [else (append (insert-everywhere-in-a-word s (first a-low))
>                  (insert-everywhere/in-all-words s (rest a-low)))]))
>
> ;;; EXAMPLE
> (= (insert-everywhere/in-all-words 'd (list (list 'l  'i  'k  'e)
>                                            (list 'p 'o)
>                                                  (list 'a 'n)))
>  (list (list 'd 'l 'i 'k 'e)
>        (list 'l 'd 'i 'k 'e)
>        (list 'l 'i 'd 'k 'e)
>        (list 'l 'i 'k 'd 'e)
>        (list 'l 'i 'k 'e 'd)
>        (list 'd 'p 'o)
>        (list 'p 'd 'o)
>        (list 'p 'o 'd)
>        (list 'd 'a 'n)
>        (list 'a 'd 'n)
>        (list 'a 'n 'd))true)
> ...
> <some post code>
>
> Produces this 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
>>
>
> If the following is commented out:
>
> ;;; EXAMPLE
> (= (insert-everywhere/in-all-words 'd (list (list 'l  'i  'k  'e)
>                                            (list 'p 'o)
>                                                  (list 'a 'n)))
>  (list (list 'd 'l 'i 'k 'e)
>        (list 'l 'd 'i 'k 'e)
>        (list 'l 'i 'd 'k 'e)
>        (list 'l 'i 'k 'd 'e)
>        (list 'l 'i 'k 'e 'd)
>        (list 'd 'p 'o)
>        (list 'p 'd 'o)
>        (list 'p 'o 'd)
>        (list 'd 'a 'n)
>        (list 'a 'd 'n)
>        (list 'a 'n 'd))true)
>
> The error disappears. Should the above example (that does not use
> check-expect and that makes improper use of =) cause such an error to
> appear? I can see that insert-everywhere/in-all-words is being called
> before insert-everywhere-in-a-word has been defined in the file. Is
> that the expected/wanted behavior for a student language?
>
> It may be useful to collect all definitions before evaluating any
> application expressions in the student languages. Is something to
> think about or is there a reason this would be undesirable?
>
> -- 
>
> Cheers,
>
> Marco
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme 



Posted on the users mailing list.