Arc Forumnew | comments | leaders | submitlogin
Recognizing and manipulating other numeric data types
1 point by dido 5203 days ago | 1 comment
Arc as it exists today appears to have support for the full Scheme numeric tower, doubtless inherited from MzScheme. Unfortunately, it seems that beyond basic arithmetic, there is little support for manipulations involving the other numeric types. One important sign of that is the following:

  arc> (type 1)
  int
  arc> (type 2.0)
  num
  arc> (type 2+3i)
  num
  arc> (type 3/4)
  num
I would have hoped that the type function would distinguish between all of these different types on the numerical tower, but it seems that it's either integers and everything else. There don't seem to be any functions available to say, obtain the denominator of a rational number, or the imaginary part of a complex. The abs function unexpectedly doesn't work with complex numbers.

Is any work being done to resolve this situation?



2 points by aw 5203 days ago | link

Using http://awwx.ws/ac,

  (= ac-tnil (ac-scheme tnil))

  (mac ac-predicate (name)
    `(def ,name (x)
       (ac-tnil ((ac-scheme ,(sym (string name "?"))) x))))

  (mac ac-predicates names
    `(do ,@(map (fn (name)
                  `(ac-predicate ,name))
                names)))

  (ac-predicates
   rational complex real integer exact-integer
   exact-nonnegative-integer exact-positive-integer
   inexact-real fixnum? zero? inexact)

  (ac-scheme (xdef numerator numerator))
  (ac-scheme (xdef denominator denominator))
  (ac-scheme (xdef real-part real-part))
  (ac-scheme (xdef imag-part imag-part))


  arc> (inexact-real 4/5)
  nil
  arc> (denominator 3/4)
  4
  arc> (imag-part 3+5i)
  5
See http://docs.plt-scheme.org/reference/numbers.html for documentation.

-----