Promises as specified in the Scheme spec are not terribly useful... but I was thinking that I could make a much cleaner implementation of lazy sequences and other things given a Scheme runtime which automatically forced promises when the promise is operated on as a value.
I was wondering if anyone's thought about doing this. Also, if it's really as hard as making every primitive (except, course, promise?, promise-forced? and friends) check and force every parameter, or if there are any neat implementation tricks, especially if there's something which can be used in gambit (like error-handler, but that seems gross. Also, incomplete and messy).
-Jason
Afficher les réponses par date
You can make a code rewriting layer that brings this behavior.
For another example of a code rewriting layer, see FrTime.
Generally somehow doing this through/atop a module system is the most conveient thing.
2013/4/29 Jason Felice jason.m.felice@gmail.com
Promises as specified in the Scheme spec are not terribly useful... but I was thinking that I could make a much cleaner implementation of lazy sequences and other things given a Scheme runtime which automatically forced promises when the promise is operated on as a value.
I was wondering if anyone's thought about doing this. Also, if it's really as hard as making every primitive (except, course, promise?, promise-forced? and friends) check and force every parameter, or if there are any neat implementation tricks, especially if there's something which can be used in gambit (like error-handler, but that seems gross. Also, incomplete and messy).
-Jason
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 04/29/2013 01:48 PM, Jason Felice wrote:
I was wondering if anyone's thought about doing this. Also, if it's really as hard as making every primitive (except, course, promise?, promise-forced? and friends) check and force every parameter, or if there are any neat implementation tricks, especially if there's something which can be used in gambit (like error-handler, but that seems gross. Also, incomplete and messy).
Try configuring gambit with "--enable-auto-forcing". I've never tried it, and I don't know whether it works.
Brad
Are you familiar with srfi-41 http://srfi.schemers.org/srfi-41?
On Mon, Apr 29, 2013 at 1:35 PM, Bradley Lucier lucier@math.purdue.eduwrote:
On 04/29/2013 01:48 PM, Jason Felice wrote:
I was wondering if anyone's thought about doing this. Also, if it's really as hard as making every primitive (except, course, promise?, promise-forced? and friends) check and force every parameter, or if there are any neat implementation tricks, especially if there's something which can be used in gambit (like error-handler, but that seems gross. Also, incomplete and messy).
Try configuring gambit with "--enable-auto-forcing". I've never tried it, and I don't know whether it works.
Brad _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 04/29/2013 02:41 PM, Phil Bewig wrote:
Are you familiar with srfi-41 http://srfi.schemers.org/srfi-41?
Sure. It seemed that the original question was more general than implementing streams.
Brad
On 2013-04-29, at 2:35 PM, Bradley Lucier lucier@math.purdue.edu wrote:
On 04/29/2013 01:48 PM, Jason Felice wrote:
I was wondering if anyone's thought about doing this. Also, if it's really as hard as making every primitive (except, course, promise?, promise-forced? and friends) check and force every parameter, or if there are any neat implementation tricks, especially if there's something which can be used in gambit (like error-handler, but that seems gross. Also, incomplete and messy).
Try configuring gambit with "--enable-auto-forcing". I've never tried it, and I don't know whether it works.
Indeed Gambit can be configured so that strict primitives do auto-forcing of promises. Just recompile Gambit with:
./configure --enable-auto-forcing make bootclean make
Then you'll be able to do this:
% gsi/gsi Gambit v4.6.7
(define a (delay (begin (pp 'forcing-a) 11))) (define b (delay (begin (pp 'forcing-b) 22))) (+ a b)
forcing-a forcing-b 33
(+ a b)
33
I just double-checked that it works.
Marc
On 04/29/2013 02:54 PM, Marc Feeley wrote:
Indeed Gambit can be configured so that strict primitives do auto-forcing of promises. Just recompile Gambit with:
./configure --enable-auto-forcing make bootclean make
Then you'll be able to do this:
<omitted stuff> I just double-checked that it works.
Well, for some value of "works". Through visual examination of the output of
grep -C 1 '(define-prim ([^#]' _num.scm
it appears that make-random-source, flonum?, and fixnum? don't force their arguments.
I didn't check the other files.
I don't know how this can be checked automatically.
Brad
On 04/29/2013 03:05 PM, Bradley Lucier wrote:
Well, for some value of "works". Through visual examination of the output of
grep -C 1 '(define-prim ([^#]' _num.scm
it appears that make-random-source, flonum?, and fixnum? don't force their arguments.
OK, make-random-source doesn't have any arguments ;-).
Brad
EGGCELLENT!!!
On Mon, Apr 29, 2013 at 3:08 PM, Bradley Lucier lucier@math.purdue.eduwrote:
On 04/29/2013 03:05 PM, Bradley Lucier wrote:
Well, for some value of "works". Through visual examination of the output of
grep -C 1 '(define-prim ([^#]' _num.scm
it appears that make-random-source, flonum?, and fixnum? don't force their arguments.
OK, make-random-source doesn't have any arguments ;-).
Brad _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Oh, why not enable by default?
(I ask because of the "check to see if it still works" comment.)
On Mon, Apr 29, 2013 at 4:09 PM, Jason Felice jason.m.felice@gmail.comwrote:
EGGCELLENT!!!
On Mon, Apr 29, 2013 at 3:08 PM, Bradley Lucier lucier@math.purdue.eduwrote:
On 04/29/2013 03:05 PM, Bradley Lucier wrote:
Well, for some value of "works". Through visual examination of the output of
grep -C 1 '(define-prim ([^#]' _num.scm
it appears that make-random-source, flonum?, and fixnum? don't force their arguments.
OK, make-random-source doesn't have any arguments ;-).
Brad _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 2013-04-29, at 4:11 PM, Jason Felice jason.m.felice@gmail.com wrote:
Oh, why not enable by default?
(I ask because of the "check to see if it still works" comment.)
Because of the run time cost of auto-forcing. If you need it and are willing to pay the cost, then you can enable it.
Marc
On 2013-04-29, at 3:05 PM, Bradley Lucier lucier@math.purdue.edu wrote:
On 04/29/2013 02:54 PM, Marc Feeley wrote:
Indeed Gambit can be configured so that strict primitives do auto-forcing of promises. Just recompile Gambit with:
./configure --enable-auto-forcing make bootclean make
Then you'll be able to do this:
<omitted stuff> I just double-checked that it works.
Well, for some value of "works". Through visual examination of the output of
grep -C 1 '(define-prim ([^#]' _num.scm
it appears that make-random-source, flonum?, and fixnum? don't force their arguments.
Primitives like "cons" and "list" should not force their arguments because they are not strict (i.e. they don't need to know the value of the arguments).
It isn't clear if type predicates are strict or not. I can see arguments both ways.
If you notice a strict primitive that should force an argument and that doesn't, please let me know and I will fix it.
Marc
On 04/29/2013 04:13 PM, Marc Feeley wrote:
Primitives like "cons" and "list" should not force their arguments because they are not strict (i.e. they don't need to know the value of the arguments).
It isn't clear if type predicates are strict or not. I can see arguments both ways.
OK. You do force pair? and boolean?; maybe you should force fixnum? and flonum?.
Brad
On Mon, Apr 29, 2013 at 4:13 PM, Marc Feeley feeley@iro.umontreal.cawrote:
Primitives like "cons" and "list" should not force their arguments because
they are not strict (i.e. they don't need to know the value of the arguments).
It isn't clear if type predicates are strict or not. I can see arguments both ways.
Hmm, I can't think of a reason to make them lazy. What's the thought?
If you notice a strict primitive that should force an argument and that
doesn't, please let me know and I will fix it.
The REPL printer doesn't auto-force.
Also, I forgot that promises are not "removed" after forcing, the way Haskell thunks are deleted. I was hoping for an air-tight abstraction. That's probably not gonna happen, huh?
I suppose that's not too bad for my purposes.
Marc
On Apr 29, 2013, at 4:31 PM, Jason Felice wrote:
On Mon, Apr 29, 2013 at 4:13 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
Primitives like "cons" and "list" should not force their arguments because they are not strict (i.e. they don't need to know the value of the arguments).
It isn't clear if type predicates are strict or not. I can see arguments both ways.
Hmm, I can't think of a reason to make them lazy. What's the thought?
Well, if you'd like to see whether something is a promise or a fixnum, you'd have to call (promise? x) first if (fixnum? x) always forces its argument.
I've been thinking about this a bit, I'm not going to use the auto-force Gambit, but perhaps the type predicates should be made consistent.
Brad
On 2013-04-29, at 5:12 PM, Bradley Lucier lucier@math.purdue.edu wrote:
On Apr 29, 2013, at 4:31 PM, Jason Felice wrote:
On Mon, Apr 29, 2013 at 4:13 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
Primitives like "cons" and "list" should not force their arguments because they are not strict (i.e. they don't need to know the value of the arguments).
It isn't clear if type predicates are strict or not. I can see arguments both ways.
Hmm, I can't think of a reason to make them lazy. What's the thought?
Well, if you'd like to see whether something is a promise or a fixnum, you'd have to call (promise? x) first if (fixnum? x) always forces its argument.
I've been thinking about this a bit, I'm not going to use the auto-force Gambit, but perhaps the type predicates should be made consistent.
I agree with the consistency argument. So now fixnum? and flonum? auto force their argument like all other type predicates (except ##promise?). Please let me know if you find other cases.
Marc
On Tue, Apr 30, 2013 at 10:46:48AM -0400, Marc Feeley wrote:
I agree with the consistency argument. So now fixnum? and flonum? auto force their argument like all other type predicates (except ##promise?). Please let me know if you find other cases.
Presumably that's only when the --autoforcing option has been set?
-- hendrik
On 2013-04-30, at 11:58 AM, Hendrik Boom hendrik@topoi.pooq.com wrote:
On Tue, Apr 30, 2013 at 10:46:48AM -0400, Marc Feeley wrote:
I agree with the consistency argument. So now fixnum? and flonum? auto force their argument like all other type predicates (except ##promise?). Please let me know if you find other cases.
Presumably that's only when the --autoforcing option has been set?
Correct. I simply added a call to the "auto-forcing" macro in those functions, which is a noop when --enable-auto-forcing is not used at configure time.
Marc