Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* a perplexing difference
@ 1996-06-23 16:01 Goffinet
  1996-06-24 19:29 ` Pierre Weis
  0 siblings, 1 reply; 2+ messages in thread
From: Goffinet @ 1996-06-23 16:01 UTC (permalink / raw)
  To: caml-list


        Hello 

        I'm unable to understand why my fonctions do return these answers 

(* first a vect swapping function*)
let swap k t=
	let prov=t.(k-1) in
	t.(k-1)<-t.(k);t.(k)<-prov;
	t
;;

(*and as I was doubting of everithing I even tried it!*)
let b=swap 3 [|1;2;3;4;5;6|];;
let c=swap 1 b;;
b;;

(*then an iterator which gives a list of the running results : as with the
Mathematica FoldList*)
let rec fold_list f l a=match l with
	[]->[a]
	|p::q->a::fold_list f q (f p a);;

(* first a test with an ordinary function, then another with swap:
        the first one does what I expected it would, 
        the other one yields  four times the same list*) 

let h u v=u+10*v;;
fold_list h [5;6;7] 0;;

fold_list swap [1;3;2] [|10;20;30;40;50|];;

(* so I made another swap_like function, I tried, It works*)
let h x t=[|-x+t.(1);t.(0)|];;
fold_list h [1;3;2] [|10;20;30;40;50|];;

I also tried to Nest my swaps on the command line (with several ((...)))): I
got the  fold_list I expected (and not the constant one)

        As always, more than an answer, a reference to some place in the
caml books where I might have found the answer would be welcomed.

        Thanks!






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

end of thread, other threads:[~1996-06-24 19:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-23 16:01 a perplexing difference Goffinet
1996-06-24 19:29 ` Pierre Weis

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