Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better range function #35

Open
FooB4r opened this issue Apr 4, 2018 · 2 comments
Open

Better range function #35

FooB4r opened this issue Apr 4, 2018 · 2 comments

Comments

@FooB4r
Copy link
Contributor

FooB4r commented Apr 4, 2018

When generating characters from their ASCII code if we want every char except the controls chars

Controls char: from 0 to 31 and 127

map [choose [range 32; const 127]] Char.chr

Non controls char:

choose [
  map [range 94] (fun n -> n + 32); (* 32 -> 126 *)
  map [range 127] (fun n -> n + 128)] (*128 -> 255*)
]

I suggest instead:

choose [range 32 127; range 128 256]

Same for alphanumeric, and all sets of contiguous values in ASCII.

@stedolan
Copy link
Owner

OK, sounds like the right thing to do is to replace:

val range : int -> int gen

with

val range : ?min:int -> lim:int -> int gen

so that

range 10
range ~lim:10
range ~min:5 ~lim:10

all work.

I'm not quite sure what the second argument should be called. range uses half-open intervals (exclusive of the upper bound), so max is the wrong word.

@FooB4r
Copy link
Contributor Author

FooB4r commented Apr 13, 2018

You can either name it ubound (which is the mathematical term for [min; ubound[)
Another solution is to have n as in "n elements" which is more computer science and range min n would give [min; min+n[
val range : ?min:int -> n:int -> int gen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants