Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Function forward declaration?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Timo.Tapiola@t...
Subject: [Caml-list] Function forward declaration?
Hi,

could someone tell me if there is some way to forward declare functions in
OCaml?

Code example, some parts of code removed:

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------

let evaluate_funcall funsig =
	let func = Funspace.get_funref funsig in
		match !func with
				Funct(s, block) -> interpret_block block;
ValNone
;;

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------

let rec evaluate_expr expr =
	match expr with
			ExpInt(int) 				->
ValInt(int)
		|	ExpFloat(float) 				->
ValFloat(float)
		|	ExpString(str) 				->
ValString(str)
		|	ExpBool(bool) 				->
ValBool(bool)
		|	ExpVar(var) 				-> let
varval = Varspace.get_varvalue var in
	
if varval = ValNone then
	
raise (Interpret_error("Error: variable not declared.\n"))
	
else
	
varval
		|	ExpBinary(ex1, bin, ex2)			->
let value1 = evaluate_expr ex1 in
	
let value2 = evaluate_expr ex2 in
	
evaluate_binary value1 bin value2
		|	ExpUnary(un, ex) 			-> let
value1 = evaluate_expr ex in
	
evaluate_unary un value1
		|	ExpCast(vartype, ex)			-> let value
=  evaluate_expr ex in
	
evaluate_cast vartype value
		|	ExpFunCall(funsig) 			->
evaluate_funcall funsig

;;

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------

let interpret_phrase phrase =
	match phrase with
			PhrExpression(exp) 	-> evaluate_expr exp; ()
		|	PhrStatement(stmt)	-> interpret_stmt stmt
		|	PhrCommand(cmd) 	-> interpret_cmd cmd;
;;

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------

let rec interpret_phrases phrases =
	match phrases with
			[] 	-> ()
		|	p::r 	-> interpret_phrase p; interpret_phrases r
;;

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------

let interpret_block block =
	match block with
			Block([])	 -> ()
		|	Block(phrases)	 -> interpret_phrases phrases
;;

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------

Call path starting from function interpret_block:

interpret_block
	interpret_phrases
		interpret_phrase
			interpret_expr
				evaluate_funcall
					interpret_block


How should I deal with this situation if there is no way to forward declare
functions?	

Thanks in advance,
	
	Timo

-------------------
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