* [Caml-list] actualize a string
@ 2003-10-23 17:39 Flavio Leonardo Cavalcanti de Moura
2003-10-23 19:32 ` Brian Hurt
0 siblings, 1 reply; 2+ messages in thread
From: Flavio Leonardo Cavalcanti de Moura @ 2003-10-23 17:39 UTC (permalink / raw)
To: caml-list
I am trying to build a procedure such that some reductions are
performed while a list (of redex) is not empty. The problem is that a
new list is needed at each step otherwise it will loop for ever. The
actual code is
let normal exp =
let l = exp :: [] in
while (matchingApp exp [] []) <> [] do
exp := (appreduction exp (hd (matchingApp exp [] [])));
exp :: l done; l;;
After the 'while' I would like to actualize the expression 'exp' with the
string (appreduction exp (hd (matchingApp exp [] []))). The problem is
that with := it does not work. How can I do that? I couldn't find anything
in the ocaml manual.
Best regards,
Flávio Leonardo.
-------------------
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] actualize a string
2003-10-23 17:39 [Caml-list] actualize a string Flavio Leonardo Cavalcanti de Moura
@ 2003-10-23 19:32 ` Brian Hurt
0 siblings, 0 replies; 2+ messages in thread
From: Brian Hurt @ 2003-10-23 19:32 UTC (permalink / raw)
To: Flavio Leonardo Cavalcanti de Moura; +Cc: caml-list
On Thu, 23 Oct 2003, Flavio Leonardo Cavalcanti de Moura wrote:
> I am trying to build a procedure such that some reductions are
> performed while a list (of redex) is not empty. The problem is that a
> new list is needed at each step otherwise it will loop for ever. The
> actual code is
>
> let normal exp =
> let l = exp :: [] in
> while (matchingApp exp [] []) <> [] do
> exp := (appreduction exp (hd (matchingApp exp [] [])));
> exp :: l done; l;;
>
> After the 'while' I would like to actualize the expression 'exp' with the
> string (appreduction exp (hd (matchingApp exp [] []))). The problem is
> that with := it does not work. How can I do that? I couldn't find anything
> in the ocaml manual.
I'm not 100% sure what you're trying to do here. Applying a function to
every member of a list is easy- look at List.iter and List.fold_left.
fold_left is especially useful for "accumulating" a result over the list.
I think what you want to do is:
let normal exp =
let f l x =
match l with
| [] -> assert false
| h :: t -> (appreduction h x) :: t
in
List.fold_left f [ exp ] (matchingApp exp [] [])
;;
but I'm not sure.
Give me a clue: what are the types of matchingApp and appreduction?
Brian
-------------------
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:[~2003-10-23 19:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-23 17:39 [Caml-list] actualize a string Flavio Leonardo Cavalcanti de Moura
2003-10-23 19:32 ` Brian Hurt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox