Dear Marc,
The procedure ordinarily reached as + , can it be reached under some alternative name in code with (declare (fixnum)) ?
Thanks, Mikael
Afficher les réponses par date
On Nov 3, 2013, at 10:01 PM, Mikael mikael.rcv@gmail.com wrote:
Dear Marc,
The procedure ordinarily reached as + , can it be reached under some alternative name in code with (declare (fixnum)) ?
Here's how I would do it:
(declare (standard-bindings) (fixnum) (not safe))
(define (double1 x) (+ ;; uses fixnum specific + (i.e. ##fx+) x x))
(define (double2 x) ((let () (declare (generic)) +) ;; uses generic + x x))
You could also call the procedure ##+, but it is not an exact replacement for + because the error handling is different (try (##+ 1 'foo)) and it must be passed 2 parameters.
Marc
2013/11/4 Marc Feeley feeley@iro.umontreal.ca
On Nov 3, 2013, at 10:01 PM, Mikael mikael.rcv@gmail.com wrote:
Dear Marc,
The procedure ordinarily reached as + , can it be reached under some
alternative name in code with (declare (fixnum)) ?
Here's how I would do it:
(declare (standard-bindings) (fixnum) (not safe))
(define (double1 x) (+ ;; uses fixnum specific + (i.e. ##fx+) x x))
(define (double2 x) ((let () (declare (generic)) +) ;; uses generic + x x))
You could also call the procedure ##+, but it is not an exact replacement for + because the error handling is different (try (##+ 1 'foo)) and it must be passed 2 parameters.
Marc
Weird, I tried for this x.scm :
(declare (standard-bindings) (fixnum)) (define x 97650736685728012900)
((let () (declare (generic)) +) x 1)
and it still goes:
$ gsc Gambit v4.7.0
(load "x.scm")
"x.scm"
,q
$ gsc Gambit v4.7.0
(compile-file "x.scm")
"x.o1"
(load "x.o1")
*** ERROR IN ##load -- (Argument 1) FIXNUM expected (fx+ 97650736685728012900 1) 1>
I get the same result when compiling the double2 example in your email above.
I tried adding another let around the +, did not resolve it.
How fix?
Thanks, Mikael
It appears to be a bug... the expansion (i.e gsc -expansion ...), which contains a call to + and not to fx+, does not match the C code generated which contains a call to fx+. I suspect an overly agressive optimization (function specialization). I will look into it. But the example Scheme code I gave is the correct way to achieve what you want.
Marc
On Nov 14, 2013, at 3:53 PM, Mikael mikael.rcv@gmail.com wrote:
2013/11/4 Marc Feeley feeley@iro.umontreal.ca
On Nov 3, 2013, at 10:01 PM, Mikael mikael.rcv@gmail.com wrote:
Dear Marc,
The procedure ordinarily reached as + , can it be reached under some alternative name in code with (declare (fixnum)) ?
Here's how I would do it:
(declare (standard-bindings) (fixnum) (not safe))
(define (double1 x) (+ ;; uses fixnum specific + (i.e. ##fx+) x x))
(define (double2 x) ((let () (declare (generic)) +) ;; uses generic + x x))
You could also call the procedure ##+, but it is not an exact replacement for + because the error handling is different (try (##+ 1 'foo)) and it must be passed 2 parameters.
Marc
Weird, I tried for this x.scm :
(declare (standard-bindings) (fixnum)) (define x 97650736685728012900) ((let () (declare (generic)) +) x
and it still goes:
$ gsc Gambit v4.7.0
(load "x.scm")
"x.scm"
,q
$ gsc Gambit v4.7.0
(compile-file "x.scm")
"x.o1"
(load "x.o1")
*** ERROR IN ##load -- (Argument 1) FIXNUM expected (fx+ 97650736685728012900 1) 1>
I get the same result when compiling the double2 example in your email above.
I tried adding another let around the +, did not resolve it.
How fix?
Thanks, Mikael