caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Function forward declaration?
@ 2004-04-06 12:14 Timo.Tapiola
  2004-04-06 12:20 ` Andrew Birkett
                   ` (4 more replies)
  0 siblings, 5 replies; 35+ messages in thread
From: Timo.Tapiola @ 2004-04-06 12:14 UTC (permalink / raw)
  To: caml-list

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


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

end of thread, other threads:[~2004-04-07 20:24 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-06 12:14 [Caml-list] Function forward declaration? Timo.Tapiola
2004-04-06 12:20 ` Andrew Birkett
2004-04-06 12:37 ` Remi Vanicat
2004-04-06 13:00   ` Issac Trotts
2004-04-06 12:53 ` Correnson Loïc
2004-04-06 15:14   ` skaller
2004-04-06 17:39   ` brogoff
2004-04-06 17:53     ` Richard Jones
2004-04-06 19:28       ` Marcin 'Qrczak' Kowalczyk
2004-04-06 22:37         ` Jon Harrop
2004-04-07  2:18         ` skaller
2004-04-07  6:01         ` Nicolas Cannasse
2004-04-07  7:31           ` Marcin 'Qrczak' Kowalczyk
2004-04-07 16:40             ` brogoff
2004-04-07 13:52           ` skaller
2004-04-07 14:15             ` Richard Jones
2002-01-03 15:21               ` Issac Trotts
2004-04-07 15:51               ` skaller
2004-04-07 16:41                 ` Richard Jones
2004-04-07 17:31                   ` Remi Vanicat
2004-04-07 17:36                     ` Richard Jones
2004-04-07 17:54                       ` Marcin 'Qrczak' Kowalczyk
2004-04-07 19:27                     ` skaller
2004-04-07 20:24                       ` Christopher Dutchyn
2004-04-07 18:04                   ` Benjamin Geer
2004-04-07 19:21                   ` skaller
2004-04-07 16:52               ` Shawn Wagner
2004-04-07 17:26               ` Basile Starynkevitch
2004-04-07 17:46                 ` Marcin 'Qrczak' Kowalczyk
2004-04-07 18:03                   ` Kenneth Knowles
2004-04-07 18:44                 ` Christopher Dutchyn
2004-04-07 14:24             ` Ville-Pertti Keinonen
2004-04-07 15:12               ` skaller
2004-04-06 12:58 ` Jean-Christophe Filliatre
2004-04-06 17:26 ` Christopher Dutchyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).