Re: How to utop to print out really large lists.

"Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> Sat, 6 Feb 2016 12:47:51 -0600
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CAM0XMJTOE5To3q3FCL_xSz3K+Xc=P3Xu_s6GsL9btF5NXyEuQw@mail.gmail.com>
This was really helpful!  Thanks!!!  Sure, List.iter can be used too, but I
like being able to customize my interface.

I think the interface is GREAT.  It's a fantastic way to test small pieces
of code before putting it all together into one big program.  The interface
is a great way to test and debug code.  Honestly, I wish more programming
languages had these interfaces.  I know that Python, Ruby and Swift have
similar interfaces to utop, but I don't think C or C++ or Java have such
interfaces, so those languages are going to be very difficult to write code
in and debug.  Just my opinion.  Thanks for the help.

Best,

Douglas.


On Fri, Feb 5, 2016 at 12:41 PM, Gabriel Scherer [email protected]
[ocaml_beginners] <[email protected]> wrote:

>
>
> There are two directives to control toplevel printer cutoffs (see
> http://caml.inria.fr/pub/docs/manual-ocaml/toplevel.html#sec256 )
>
> #print_depth <int>
>   Limit the printing of values to a maximal depth of n.
> #print_length <int>
>   Limit the number of value nodes printed to at most n.
>
> The "depth" refers to the depth of nested datastructures. In your case,
> you want to change #print_length.
> For a list of length 1000,
>   #print_length 1001;;
> should work fine -- the list brackets count for 1, or something -- or any
> higher value.
>
> On Fri, Feb 5, 2016 at 1:04 PM, Douglas Lewit [email protected]
> [ocaml_beginners] <[email protected]> wrote:
>
>>
>>
>> Sorry about the bad English.  The title should have read, "How to
>> *customize* utop to print out really large lists".  Sorry if the
>> original title was a little confusing or misleading.
>>
>> On Fri, Feb 5, 2016 at 12:02 PM, Douglas Lewit [email protected]
>> [ocaml_beginners] <[email protected]> wrote:
>>
>>>
>>>
>>> Hi everyone,
>>>
>>> So let's say that I'm using the following function to create a list of
>>> random integers:
>>>
>>> *let rec randomList lower upper size = if size = 0 then [ ] else ( lower
>>> + Random.int ( upper - lower + 1 )*
>>> *:: ( randomList lower upper ( size - 1 ) ) ;;*
>>>
>>> The function works great!  I end up with a list of length size having
>>> random integers in the range lower..upper ( including the endpoints of that
>>> range ).  But here's the catch.
>>>
>>> Let's say that I do this:
>>>
>>> *let dougsList = randomList 1 1000 1000 ;;*
>>>
>>> Okay, great.... but if I'm using the *utop interface* for OCaml, then I
>>> can only see about the first 350 ( approximately ) elements of my random
>>> list.  Is there some setting in utop that I can change so that utop is
>>> forced to print out the entire list for the sake of my visual inspection.
>>> I realize that visually inspecting a list of 1,000 elements sounds rather
>>> crazy and unrealistic, but the user of the interface should have that
>>> option.
>>>
>>> Thanks for helping me solve this problem.
>>>
>>> Best,
>>>
>>> Douglas Lewit
>>>
>>>
>>>
>>
>>
>>
> 
>