[plt-scheme] Character problem

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue May 31 10:06:55 EDT 2005

Oh, no. Sorry. That's what you want for `+' and other operators. For
one-digit numbers, you'll want

  (define (char->number c) (string->number (string c)))

for multi digit numbers, perhaps as a list of characters, you'll want:

  ;; chars->number : (listof char) -> number or false
  ;; returns #f when the chars don't form a valid number
  (define (chars->number cs) (string->number (apply string cs)))

hth,
Robby

At Tue, 31 May 2005 08:59:55 -0500, Robby Findler wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Probably you want to call this function
> 
>   (define (char->symbol c) (string->symbol (string c)))
> 
> on each element of your list.
> 
> Robby
> 
> At Tue, 31 May 2005 09:52:53 -0400, Todd Dobmeyer wrote:
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> > 
> > I am new to using Scheme. I am working on a Scheme project for a class 
> > at Wright State University. We have to read in RPN (reverse polish 
> > notation) expressions from a text file, convert this RPN string to a 
> > list, and then manipulate the list to work with (eval) to find the 
> > answer. I have everything working except for one part. That is when I 
> > am trying to convert the string to a list. I can use the string-ref 
> > with a counter in a loop to add each non-space character to the list 
> > because we are guaranteed to have numbers or operators only. My 
> > problem is that string-ref returns a character as #\5, which is the 
> > way to define a character. But eval cannot work on individual 
> > characters if you have a list of them. It needs the list to be '(+ 5 
> > 3) and not '(#\+ #\5 #\3) if I understand this correctly. Is there a 
> > simple way to truncate the #\ off each item? Thanks for any help you 
> > have!
> > 
> > Todd Dobmeyer



Posted on the users mailing list.