How to determine signed integer?

For the Compleat Fan
Locked
Jeremy Dunn
Posts: 95
Joined: Wed Oct 13, 2004 8:02 pm
Location: Bellingham WA

How to determine signed integer?

Post by Jeremy Dunn »

I have a situation where I want to determine if my function received +2 vs just 2 from the user. If I use "integer?" as my test both versions return true. If I try using "string" both values return "2". Is there any way to identify a positive signed integer versus a positive unsigned integer? If not, could "string" be modified to return the input literally?

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

I think that only 'format is able to distinguish those..
-- (define? (Cornflakes))

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

A thought: if r is "+2" and s is "2", then the following is true:

Code: Select all

(and (= (eval-string r) (eval-string s)) (!= (length r) (length s)))
ie they're the same thing but different lengths. Trouble is, it might be true for other pairs of strings...?

Locked