[plt-scheme] What's wrong with define inside begin which is inside if

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Sep 4 11:28:57 EDT 2006

begin sequences a series of _expressions_. A definition is not an  
expression.

In case you know C or some other {} language, imagine writing this

  int f(int x) {
    int g(int y) { return x + y; }
    return g(20);
  }

It would signal an error, too, because a function definition is not a  
variable definition, which are the only things allowed inside of  
procedures. -- Matthias


On Sep 4, 2006, at 10:21 AM, Andre Mayers wrote:

> If I try to evaluate the following expression
>
>     (if (< 1 0)
>         (begin (define z 4)
>                (* z 2))
>         3)
>
> I got the following answer
>
>     define: not allowed in an expression context in: (define z 4)
>
>
> What is the principle behind that ?
> I can't find the answer with Revised^5 Report on the Algorithmic  
> Language Scheme
> ----
>
> André Mayers, Ph.D., M. Ps.
> professeur agrégé
> Département d'informatique
> Université de Sherbrooke
> Sherbrooke (Québec) Canada J1K 2R1
> tél: +1 819-821-8000 poste 62041
> fax: +1 819-821-8200
> andre.mayers at usherbrooke.ca
> http://www.dmi.usherb.ca/~amayers
>
>
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.