List Info

Thread: "ocaml_beginners"::[] What's wrong with this code?




"ocaml_beginners"::[] What's wrong with this code?
user name
2006-12-19 05:51:15

Hi,
I'm having difficulties with a function that produces a synstax error
but I just don't get it why. Maybe somebody can give me a hint. This is
the function.

(* wrapper for ghostparticles routine in Vectorop *)
let get_ghostparticles ~particle:particle =
let list_of_ghostparticles = Vectorop.ghostparticle_loc particle.r
in let rec newgparticles list_of_ghostparticles ?(newghostparts = []) =
match list_of_ghostparticles with
[] -> newghostparts
| (gp :: gplist) -> let newgp = { r = gp; v = particle.v } in
newgparticles gplist (newgp :: newghostparts)

The error message looks like this.

Characters 741-743:
newgparticles gplist (newgp :: newghostparts);;
^^
Syntax error

What is the syntax error here. newghostparts is optional but even if it
is omitted I should have an empty list I can prepend newgp to. Any
hints?

Cheers,
Christian

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Re: What's wrong with this code?
user name
2006-12-19 06:54:56

So you defined a function "get_ghostparticles". Inside it you defined
"list_of_ghostparticles"; and "newgparticles". But other than that,
your function won't be doing anything. After defining the embedded
functions, you need to add "in" and then have your function perform
the actions you want.

This is something similar to what your code looks like:

let myfunction arg1 arg2 =
let subfunction1 subarg1 subarg2 =
dostuff in
let subfunction subarg1 subarg2 =
dostuff

But it needs to be more like

let myfunction arg1 arg2 =
let subfunction1 subarg1 subarg2 =
do_stuff in
let subfunction2 subarg1 subarg2 =
do_different_stuff in
subfunction1 (subfunction2 arg1 arg2)

or something like that, depending on what subfunction1 and
subfunction2 do.

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] What's wrong with this code?
user name
2006-12-19 16:26:07

2006/12/19, Christian Lerrahn < ocaml%40penpal4u.net">ocamlpenpal4u.net>:
> Hi,
> I'm having difficulties with a function that produces a synstax error
>; but I just don't get it why. Maybe somebody can give me a hint. This is
> the function.
>
> (* wrapper for ghostparticles routine in Vectorop *)
> let get_ghostparticles ~particle:particle =
> let list_of_ghostparticles = Vectorop.ghostparticle_loc particle.r
> in let rec newgparticles list_of_ghostparticles ?(newghostparts = []) =
> match list_of_ghostparticles with
> [] -> newghostparts
> | (gp :: gplist) -> let newgp = { r = gp; v = particle.v } in
> newgparticles gplist (newgp :: newghostparts)

your problem is that, at the exception of toplevel let, all let must
have their in.

BUt here, the let list_of_ghostparticles, and let newgp have their in,
but not the
let rec newgparticles: you define it, but you don't use it.

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )