Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Goffinet <goffinet@cit-novell.univ-st-etienne.fr>
To: caml-list@pauillac.inria.fr
Subject: a perplexing difference
Date: Sun, 23 Jun 1996 18:01:53 +0200 (MET DST)	[thread overview]
Message-ID: <1.5.4.16.19960623172313.130f404e@cit-novell.univ-st-etienne.fr> (raw)


        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!






             reply	other threads:[~1996-06-24 19:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-23 16:01 Goffinet [this message]
1996-06-24 19:29 ` Pierre Weis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1.5.4.16.19960623172313.130f404e@cit-novell.univ-st-etienne.fr \
    --to=goffinet@cit-novell.univ-st-etienne.fr \
    --cc=caml-list@pauillac.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox