Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Hash tables keys and values
@ 2002-05-23 18:24 Vincent Foley
  2002-05-23 18:55 ` Fermin Reig
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Foley @ 2002-05-23 18:24 UTC (permalink / raw)
  To: OCaml Mailing list

Hi, I have a hashtables of all 26 characters of the alphabet: these are
my keys.  They are all associated with the number of times they appear
in an arbitrary text file.  Once I have my hash table complete, I would
like to print each key with its associated value.  How would I do this?
Right now I only have the values:

   Hashtbl.iter (fun k -> Printf.printf "%d\n") myhash;

Is there any way I could print both keys and values?

Thank you,

Vincent Foley


-- 

Vincent Foley-Bourgon
Email: vinfoley@iquebec.com
Homepage: http://darkhost.mine.nu:81
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Hash tables keys and values
  2002-05-23 18:24 [Caml-list] Hash tables keys and values Vincent Foley
@ 2002-05-23 18:55 ` Fermin Reig
  0 siblings, 0 replies; 2+ messages in thread
From: Fermin Reig @ 2002-05-23 18:55 UTC (permalink / raw)
  To: vinfoley; +Cc: caml-list


> Once I have my hash table complete, I would like to print each key
> with its associated value.  How would I do this?  Right now I only
> have the values:
> 
>    Hashtbl.iter (fun k -> Printf.printf "%d\n") myhash;
> 
> Is there any way I could print both keys and values?
> 
> Thank you,
> Vincent Foley

Read the OCaml manual:

val iter : ('a -> 'b -> unit) -> ('a, 'b) Hashtbl.t -> unit

Hashtbl.iter f tbl applies f to all bindings in table tbl. F RECEIVES
THE KEY AS FIRST ARGUMENT, AND THE ASSOCIATED VALUE AS SECOND
ARGUMENT. The order in which the bindings are passed to f is
unspecied. Each binding is presented exactly once to f.

(My emphasis) Hope that helps,
Fermin
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-23 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-23 18:24 [Caml-list] Hash tables keys and values Vincent Foley
2002-05-23 18:55 ` Fermin Reig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox