Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Scheme Programming Language

newbie: char-numeric?


Hi all,

I'm still sorting my way through the available procedures in Scheme and the
functionality of char testing has be a tad baffled.

For example, if I was uncertain about the nature of an object being passed
to a procedure then I would like to test it (identify it) and then branch
according to what it was.

This code won't work: (char-alphabetic? "a")
;==> char-alphabetic?: expects argument of type <character>; given "a"

Now I know that "a" is a string literal and not a char-alphabetic? object.
I would have expected (wrongly) for the expression to resolve as #f rather
than cough blood and die.

You see, procedures like number? string? char? all resolve as #t or #f
irrespective of whatever is used as the argument (so far as I can tell).
eg: (char? "a") ;==> #f and (number? "a") ; ==> #f.

(a) Is there a hierarchy on these sorts of procedures?  As is, first
determine (char? foo) before then asking questions about precisely what sort
of char it might be if the first is true?
(b) Are there any other procedures (testing object types) that behave in the
same way as char-numeric? (excluding the other char-type procedures since
they too behave the same: char-alphabetic? char-punctuation?)?

Thanks,

Mike

Mike <mcu87@bigpond.net.au> wrote:
> This code won't work: (char-alphabetic? "a")
> ;==> char-alphabetic?: expects argument of type <character>; given "a"

> Now I know that "a" is a string literal and not a char-alphabetic? object.
> I would have expected (wrongly) for the expression to resolve as #f rather
> than cough blood and die.

CHAR-ALPHABETIC? expects a char. For your purpose you want to
combine it with a type predicate (which accepts any type):

(lambda (x) (and (char? x) (char-alphabetic? x)))

--
Nils M Holm <n m h @ t 3 x . o r g> -- http://t3x.org/nmh/

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc