[plt-scheme] HTDPExercise 14.1.3

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Jun 10 17:29:30 EDT 2009

((symbol? ...) ...)
  ^^^^^^^^^^^^^

1. (foo ...) means apply function foo to arguments.

2. ((symbol? ...) ...)

is NOT the name of a function. And it's highlighted. So you don't  
mean to write this here.

Follow the receipe.


On Jun 10, 2009, at 4:47 PM, aditya shukla wrote:

> I was solving  this exercise from htdp , its been quite some days  
> since i wrote a program in scheme .I am getting this error which i  
> am not able to sort out .Can someone please help me with this.
>
> ;data definition
> (define-struct child (father mother name date eyes))
> ;oldest generation
> (define Carl (make-child empty empty 'Carl 1926 'green))
> (define Bettina (make-child empty empty 'Bettina 1926 'green))
>
> ;; Middle Generation:
> (define Adam (make-child Carl Bettina 'Adam 1950 'yellow))
> (define Dave (make-child Carl Bettina 'Dave 1955 'black))
> (define Eva (make-child Carl Bettina 'Eva 1965 'blue))
> (define Fred (make-child empty empty 'Fred 1966 'pink))
>
> ;; Youngest Generation:
> (define Gustav (make-child Fred Eva 'Gustav 1988 'brown))
>
>
> ;A family-tree-node (short: ftn) is either
>
>  ;  1.
>
>    ;  empty; or
>    ;2.
>
>     ;  (make-child f m na da ec)
>      ; where f and m are ftns, na
>       ;and ec are symbols, and da is a number.
> ;contract of count-persons ftn(family tree node) -> number
> ;Purpose :This function takes a family tree node and computes the  
> number of persons in that node
> ;examples empty -> 0 ,carl ->1 , bettina -> 1 ,  adam , dave , eva - 
> > 3 , fred->1 , gustav-> 5
> ;template(define count-persons (lambda (ftn) (cond [(empty? ftn )] 
> [else (count-persons (child-father ftn)) (count-persons (child- 
> mother  ftn)) (child-name ftn) (child-date ftn) (child-eyes ftn)])))
> (define (count-persons  a-ftree)
>   (cond
>     [(empty? a-ftree) 0]
>     [else ((symbol? (child-name a-ftree))  (+ 1 (count-persons(or  
> (child? (child-father a-ftree) ) (child? (child-mother a- 
> ftree) )))))]))
>
> (count-persons Fred)
>
>
>
>
> function call: expected a name after an open parenthesis, but found  
> something else
>
>
> Thanks,
> Aditya
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.