[Chicken-users] Problems with rationals

2012-04-09 Thread Mark Carter
Is this a bug in chicken?
(rational? 6/10) = #f

Also
(* 1.0 5/2)
produces
Error: (*) bad argument type: 5/2

Call history:

syntax  (* 1.0 5/2)
eval(* 1.0 5/2)


CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.0.5-st 
linux-unix-gnu-x86 [ manyargs dload ptables ]
compiled 2012-03-07 on miro (Linux)

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Problems with rationals

2012-04-09 Thread Peter Bex
On Mon, Apr 09, 2012 at 09:00:10PM +0100, Mark Carter wrote:
 Is this a bug in chicken?
   (rational? 6/10) = #f

Chicken by itself doesn't support ratnums.  You'll need the
numbers egg to get the full numeric tower (including arbitrarily
large numbers and complex numbers).

 Also
   (* 1.0 5/2)
 produces
 Error: (*) bad argument type: 5/2

If I want to reproduce this, do I need to type in anything else?
It doesn't happen here.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Problems with rationals

2012-04-09 Thread Thomas Chust
On Mon, 2012-04-09 at 21:00 +0100, Mark Carter wrote:
 Is this a bug in chicken?
   (rational? 6/10) = #f
 
 Also
   (* 1.0 5/2)
 produces
 Error: (*) bad argument type: 5/2
 [...]

Hello,

this looks strange. While CHICKEN does not support exact fractions out
of the box, reading a number in fractional notation should simply issue
a warning and return a floating point number. Also, when I apply the
rational? predicate from CHICKEN's core library to a floating point
number I get the answer #t:

$ csi -n

CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.4 (rev ad149e7)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2012-02-07 on hd-t1179cl (Linux)

#;1 (rational? 5/2)

Warning: cannot represent exact fraction - coerced to flonum: 5/2
#t
#;2 (* 1.0 5/2)

Warning: cannot represent exact fraction - coerced to flonum: 5/2
2.5

One way I can reproduce your problems is by loading but not importing
the numbers extension library, which adds support for arbitrary
precision arithmetic and exact fractions to CHICKEN:

$ csi -n

[...]

#;1 (require-library numbers)
; loading /usr/lib/chicken/6/numbers.so ...
#;2 (rational? 5/2)
#f
#;3 (* 1.0 5/2)

Error: (*) bad argument type: 5/2

Call history:

syntax  (* 1.0 5/2)
eval(* 1.0 5/2)   --

This, however, is a misuse of the numbers library. The problem here is
that by loading the library the standard reader of CHICKEN is modified.
The fractional number notation then produces objects not understood by
CHICKEN's core libraries and to work with them you also have to import
the versions of arithmetic operators and numerical predicates that are
provided by the numbers library.

Ciao,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Problems with rationals

2012-04-09 Thread John Cowan
Thomas Chust scripsit:

 One way I can reproduce your problems is by loading but not importing
 the numbers extension library, which adds support for arbitrary
 precision arithmetic and exact fractions to CHICKEN:

Nice catch.  A warning should be put in the numbers egg documentation
not to do that.

-- 
John Cowan  co...@ccil.org  http://ccil.org/~cowan
The penguin geeks is happy / As under the waves they lark
The closed-source geeks ain't happy / They sad cause they in the dark
But geeks in the dark is lucky / They in for a worser treat
One day when the Borg go belly-up / Guess who wind up on the street.

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Problems with rationals

2012-04-09 Thread Mark Carter
 If I want to reproduce this, do I need to type in anything else?
 It doesn't happen here.

After some experimenting, the statistics eggs seems to introduce some 
peculiarity. Here's a session:

--
#;1 (* 1.0 5/2)

Warning: cannot represent exact fraction - coerced to flonum: 5/2
2.5
#;2 (use statistics)
#;3 (* 1.0 5/2)

Error: (*) bad argument type: 5/2

Call history:

syntax  (* 1.0 5/2)
eval(* 1.0 5/2)   --
#;3 (use numbers)
#;4 (* 1.0 5/2)
2.5

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Problems with rationals

2012-04-09 Thread Peter Bex
On Mon, Apr 09, 2012 at 09:39:06PM +0100, Mark Carter wrote:
  If I want to reproduce this, do I need to type in anything else?
  It doesn't happen here.
 
 After some experimenting, the statistics eggs seems to introduce some 
 peculiarity. Here's a session:
 
 --
 #;1 (* 1.0 5/2)
 
 Warning: cannot represent exact fraction - coerced to flonum: 5/2
 2.5
 #;2 (use statistics)
 #;3 (* 1.0 5/2)
 
 Error: (*) bad argument type: 5/2
 
 Call history:
 
 syntax  (* 1.0 5/2)
 eval(* 1.0 5/2)   --
 #;3 (use numbers)
 #;4 (* 1.0 5/2)
 2.5

This is a known problem with the numbers egg, see Thomas's post.
I didn't expect it to turn up in this particular way; a more common
way is to have a library/module that uses numbers which passes the
number to procedures in a library which doesn't, and then tries to
perform calculations on it.

The only way to truly fix this is to add numbers to core; the
way it extends the reader is a bit of a hack and it doesn't truly
replace the procedures from the Scheme module.  Even if it did, compiled
code often calls C functions directly which bypasses any overwriting
the numbers egg might do at the Scheme level; that's why it doesn't
even try to do this at all.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Problems with rationals

2012-04-09 Thread John Cowan
Peter Bex scripsit:

 The only way to truly fix this is to add numbers to core; the way it
 extends the reader is a bit of a hack and it doesn't truly replace
 the procedures from the Scheme module.  Even if it did, compiled code
 often calls C functions directly which bypasses any overwriting the
 numbers egg might do at the Scheme level; that's why it doesn't even
 try to do this at all.

I proposed an alternative to Felix several years ago, namely to do things
in the core via hooks which can be set at run-time when you load the
numbers egg.  That way everything behaves systematically except compiled
code that inlines procedures based on type information.  Felix said this
was too big and comprehensive a change.

But, blast it, if little Chibi can include a full numeric tower, why
should Chicken position itself with RScheme and VX, plus a bunch of
broken Schemes that always return a fixnum when multiplying fixnums,
even if it's the wrong one?

See http://trac.sacrideo.us/wg/wiki/NumericTower for a table of which
Schemes support which numeric tower features.

-- 
First known example of political correctness:   John Cowan
After Nurhachi had united all the other http://www.ccil.org/~cowan
Jurchen tribes under the leadership of the  co...@ccil.org
Manchus, his successor Abahai (1592-1643)
issued an order that the name Jurchen should   --S. Robert Ramsey,
be banned, and from then on, they were all   The Languages of China
to be called Manchus.

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users