[plt-scheme] Beginner question

From: James Jackson (james_e_jackson at yahoo.com)
Date: Fri Sep 30 18:46:45 EDT 2005

Anders Persson wrote:

>Hi!

>I am trying to learn PLT and yesterday i try to write
>a program with 2 functions that asks for user namen
>och write Hello + user namen
>
>The code was
>-------------------------------------------------------------------
>(define ask-user-name
>  (begin
>  (display "Hi whats your name? ")
>  (read-line)))

Problem # 1:

I think that you are intending to set the variable
ask-user-name equal to a function that asks the user
his name and returns the resulting string.  What the
above code does is ask the user for his name and set
the variable to the resulting string.

I think what you wanted to do is 

(a)

(define ask-user-name
   (lambda () 
      (begin ....

or  (b)


(define (ask-user-name)
   (begin ...

which is really just shorthand for (a).

>
>(define say-hello-to-user
>  (lambda (name)
>    (display "Hello ")
>    (display name)))
>
>(define name (string->symbol ask-user-name))
>(say-hello-to-user name)

Problem #2:

I think that what you want here is

(define name (string->symbol (ask-user-name)))

and you just left out the extra parentheses.  In this
case Problems # 1 and 2 cancelled each other out and
resulted in working code. This is why 

(define name (ask-user-name)),

which was correctly written, didnt work and the
string->symbol version, which wasn't, did.

I hope this is helpful.

James





		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


Posted on the users mailing list.