[plt-scheme] Let, cond and local

From: Joe Marshall (jrm at ccs.neu.edu)
Date: Tue Jan 6 09:22:41 EST 2004

"Ricardo Massamitsu Nonomura" <nonomura at moimeichego.de> writes:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Hi All,
>
> I'm getting a little confused, in the Revised5 Report on the Algorithmic
> Language Scheme, on section 4.2.2 the constructs let, let* and letrec
> are described. But in the first line of my "homework" already in the
> first line I get the error msg:
>
> function call: expected a defined name or a primitive operation name
> after an open parenthesis, but found something else in: (m (cond (((<=
> 1800 j 1899) 23) ((<= 1900 j 2199) 24) (else (error "falsches Jahr")))))

  (m (cond (((<= 1800 j 1899) 23) ((<= 1900 j 2199) 24) (else (error "falsches Jahr")))))

You have too many parenthesis.

Remember that COND takes a series of clauses where each clause has a
test and a consequence.  The first clause is: 

 (((<= 1800 j 1899) 23) ((<= 1900 j 2199) 24) (else (error "falsches Jahr")))

So the test is:

 ((<= 1800 j 1899) 23)

Which is a function call whose operator is:

 (<= 1800 j 1899) and whose argument is 23.

Try this:

  (m (cond ((<= 1800 j 1899) 23)
           ((<= 1900 j 2199) 24)
           (else (error "falsches Jahr"))))

Now the first clause is  ((<= 1800 j 1899) 23)

So the test is 
  (<= 1800 j 1899)

Which is a function call whose operator is <= and whose arguments are
1800, j, and 1899.

> I guess that the nested let* is wrong, but I cannot pass through the
> first...
>
> (define (oster j) (let* ((m (cond (((<= 1800 j 1899) 23)
>                                    ((<= 1900 j 2199) 24)
>                                    (else (error "falsches Jahr")))))

This COND is broken, too.

>                          (n (cond (((<= 1800 j 1899) 4)
>                                    ((<= 1900 j 2099) 5)
>                                    ((<= 2100 j 2199) 6))))

>                          (a (modulo j 19))
>                          (b (modulo j 4))
>                          (c (modulo j 7))
>                          (d (modulo (+ (* 19 a) m) 30))
>                          (e (modulo (+ (* 2 b) (* 4 c) (* 6 d) n) 7)))
>                     (let* (tag (if (> (+ d e) 9) (+ d e -9) (+ 22 d e)))
>                       (monat (if (> (+ d e) 9) 'April 'Maerz))))

This one is ok, though.

>   (if (= monat 'April) (cond ((= tag 26) (list 19 monat j))
>                              ((and (= tag 25) (= d 28) (= e 6) (> a 9))
> (list 18 monat j)) (list tag monat j))))
> ----------------
>
> TIA,
>
>         ________________ _..----====~~~~====--,
> =====  (______________I_)'- = ,~~----===*===----~~~~
> ===== / /__..---=='---./
> ----- `---'---._________.' Ricardo Massamitsu Nonomura
> E-Mail: massamitsu_nonomura at hotmail.com
>             nonomura at moimeichego.de 
> Homepage: www.moimeichego.de
> ICQ: 7234230
> PGP: Oxo70F0B5C



Posted on the users mailing list.