Re: [racket-users] change 'random' contract to allow zero in first position?
https://github.com/racket/racket/pull/1626 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] change 'random' contract to allow zero in first position?
> On Mar 3, 2017, at 12:02 PM, Daniel Prager wrote: > > > > On Sat, Mar 4, 2017 at 6:21 AM, John Clements > wrote: > > > On Mar 2, 2017, at 3:00 PM, Daniel Prager wrote: > > > > While we're at it, please allow negative arguments too, to allow for cases > > such as > > > > (random -100 100) > > Well, that’s different; that’s actually changing the implementation. I’m not > proposing that… > > > The implementation looks fine to me. In pre-base.rkt the relevant lines > should work fine with -ve arguments as long as the inequality constraint > holds. E.g. > > (+ x (random (- y x))) with x=-100, y=100 > -> (+ -100 (random 200)) Sure, sounds good to me; want to submit a pull request? (NB: I speak for no one but myself, here.) John -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] change 'random' contract to allow zero in first position?
On Sat, Mar 4, 2017 at 6:21 AM, John Clements wrote: > > > On Mar 2, 2017, at 3:00 PM, Daniel Prager > wrote: > > > > While we're at it, please allow negative arguments too, to allow for > cases such as > > > > (random -100 100) > > Well, that’s different; that’s actually changing the implementation. I’m > not proposing that… > > The implementation looks fine to me. In pre-base.rkt the relevant lines should work fine with -ve arguments as long as the inequality constraint holds. E.g. (+ x (random (- y x))) with x=-100, y=100 -> (+ -100 (random 200)) Dan -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] change 'random' contract to allow zero in first position?
> On Mar 2, 2017, at 2:06 PM, Jay McCarthy wrote: > > I think that the contract is overly specific on the 2 argument case. > But on the 1 argument case, I don't think 0 makes sense: > > "When called with an integer argument k, returns a random exact > integer in the range 0 to k-1."[k <- 0] > =_v > "When called with an integer argument 0, returns a random exact > integer in the range 0 to -1.” Right; I’m not proposing a change to the one-argument case, only to the two-argument case. John -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] change 'random' contract to allow zero in first position?
> On Mar 2, 2017, at 3:00 PM, Daniel Prager wrote: > > While we're at it, please allow negative arguments too, to allow for cases > such as > > (random -100 100) Well, that’s different; that’s actually changing the implementation. I’m not proposing that… John -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] change 'random' contract to allow zero in first position?
While we're at it, please allow negative arguments too, to allow for cases such as (random -100 100) Dan -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] change 'random' contract to allow zero in first position?
I think that the contract is overly specific on the 2 argument case. But on the 1 argument case, I don't think 0 makes sense: "When called with an integer argument k, returns a random exact integer in the range 0 to k-1."[k <- 0] =_v "When called with an integer argument 0, returns a random exact integer in the range 0 to -1." Jay On Thu, Mar 2, 2017 at 4:41 PM, 'John Clements' via Racket Users wrote: > I have a bunch of students this quarter that are writing code like this: > > (- (random 1 9) 1) > > Why? because they tried writing > > (random 0 8) > > and got a contract error, to wit: > > > random: contract violation > expected: (integer-in 1 4294967087) > given: 0 >> > > I’m assuming that this contract was written by someone who imagined that the > recipient would realize that the first argument could be omitted entirely, > but my sample suggests that’s not the case. > > Would it be all right to just change the contract to allow zero as a first > argument? I’d be happy to submit a pull request, if so. > > John > > > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- -=[ Jay McCarthy http://jeapostrophe.github.io]=- -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=- -=[ Moses 1:33: And worlds without number have I created; ]=- -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] change 'random' contract to allow zero in first position?
I have a bunch of students this quarter that are writing code like this: (- (random 1 9) 1) Why? because they tried writing (random 0 8) and got a contract error, to wit: random: contract violation expected: (integer-in 1 4294967087) given: 0 > I’m assuming that this contract was written by someone who imagined that the recipient would realize that the first argument could be omitted entirely, but my sample suggests that’s not the case. Would it be all right to just change the contract to allow zero as a first argument? I’d be happy to submit a pull request, if so. John -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.