File: 140-ref.ml

package info (click to toggle)
perl4caml 0.9.5-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 512 kB
  • ctags: 788
  • sloc: ml: 1,572; ansic: 957; makefile: 186; perl: 45
file content (33 lines) | stat: -rw-r--r-- 800 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(* Reference, dereference.
 * $Id: 140-ref.ml,v 1.2 2005/04/14 13:05:12 rich Exp $
 *)

open Perl

let () =
  let sv = sv_of_int 42 in
  let sv = scalarref sv in
  assert (sv_type sv = SVt_RV);
  assert (reftype sv = SVt_IV);
  let sv = deref sv in
  assert (42 = int_of_sv sv);

  let av = av_of_string_list [ "foo"; "bar" ] in
  let sv = arrayref av in
  assert (sv_type sv = SVt_RV);
  assert (reftype sv = SVt_PVAV);
  let av = deref_array sv in
  assert (2 = av_length av);

  let hv = hv_empty () in
  hv_set hv "foo" (sv_of_int 1);
  hv_set hv "bar" (sv_of_int 2);
  let sv = hashref hv in
  assert (sv_type sv = SVt_RV);
  assert (reftype sv = SVt_PVHV);
  let hv = deref_hash sv in
  assert (1 = int_of_sv (hv_get hv "foo"));
  assert (2 = int_of_sv (hv_get hv "bar"));
;;

Gc.full_major ()