caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* newbie: how to call a function with multiple parameters?
@ 2008-08-04 18:32 Ben Aurel
  2008-08-05 11:40 ` [Caml-list] " asmadeus77
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ben Aurel @ 2008-08-04 18:32 UTC (permalink / raw)
  To: caml-list

hi
yeah - the question is low, but I-m struggling on different frontiers

/////////////// print_logic.ml ///////////////////////////////
````````````````````````````````````````
1 let print_logic a b =
2 Printf.printf "a and b is %B\n" (a && b);
3 Printf.printf "a or b is %B\n" (a || b);
4 Printf.printf "not a is %B\n" (not a)    (* Q1 *)
5
6 print_logic(true, false);; (* Q2 *)

```````````````````````````````````````

Problem: the code doesn't compile and I don't find any help on the web.

Questions:
 (* Q1 *): Somehow I don't get the concept with ";" and ";;". On line
4 do I need to end the statement with semicolon double-semicolon or
nothing?

 (* Q2 *): How can I pass those parameters?


Maybe there is something that's else wrong.

thanks
ben


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

* Re: [Caml-list] newbie: how to call a function with multiple parameters?
  2008-08-04 18:32 newbie: how to call a function with multiple parameters? Ben Aurel
@ 2008-08-05 11:40 ` asmadeus77
  2008-08-05 11:46 ` micha
  2008-08-05 13:26 ` Peng Zang
  2 siblings, 0 replies; 4+ messages in thread
From: asmadeus77 @ 2008-08-05 11:40 UTC (permalink / raw)
  To: Ben Aurel; +Cc: caml-list

Hello,
semicolons are separator inside sentences, that is, just like in C
(you've had theses right)
double semicolons are to tell the compiler you're ending a sentence;
theses can be ommited when there is no ambiguity in the syntax, that
is when there is another "main" let after it. Here, you need them on
line 4.

As for arguments, ocaml works by passing one argument, then gives back
another function, then takes another argument, returns another
function, etc... If you wanted to have a tuple, you'd define the
function with "let print_logic (a, b) ="
Here, since you've defined it with "a b", you need to call it with a
THEN with b. That is : "print_logic true false"

Hope this helps,
Asmadeus


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

* Re: [Caml-list] newbie: how to call a function with multiple parameters?
  2008-08-04 18:32 newbie: how to call a function with multiple parameters? Ben Aurel
  2008-08-05 11:40 ` [Caml-list] " asmadeus77
@ 2008-08-05 11:46 ` micha
  2008-08-05 13:26 ` Peng Zang
  2 siblings, 0 replies; 4+ messages in thread
From: micha @ 2008-08-05 11:46 UTC (permalink / raw)
  To: caml-list

On Monday 04 August 2008 20:32:36 Ben Aurel wrote:
> hi
> yeah - the question is low, but I-m struggling on different frontiers
>
> Questions:
>  (* Q1 *): Somehow I don't get the concept with ";" and ";;". On line
> 4 do I need to end the statement with semicolon double-semicolon or
> nothing?

the double semicolon ends the definition of types / functions / objects...
the single semicolon ends a statement. So to end the definition of print_logic 
you need the double semicolon in your example.
There are cases where you can omit the double semicolon, I write them allways, 
for visual aid ( and I can search for them in my editor).

>  (* Q2 *): How can I pass those parameters?

the same way as to printf, without delimiters:
print_logic true false

 Michael



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

* Re: [Caml-list] newbie: how to call a function with multiple parameters?
  2008-08-04 18:32 newbie: how to call a function with multiple parameters? Ben Aurel
  2008-08-05 11:40 ` [Caml-list] " asmadeus77
  2008-08-05 11:46 ` micha
@ 2008-08-05 13:26 ` Peng Zang
  2 siblings, 0 replies; 4+ messages in thread
From: Peng Zang @ 2008-08-05 13:26 UTC (permalink / raw)
  To: caml-list; +Cc: Ben Aurel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You don't pass arguments like you do in C or Java.  In those languages you 
might do:

  somefunction(arg1, arg2, arg3)

In OCaml, you do:

  somefunction arg1 arg2 arg3

In OCaml, "(arg1, arg2, arg3)" means create a 3-tuple.  "somefunction(arg1, 
arg2, arg3)" is interpreted as make a 3-tuple and call "somefunction" on that 
tuple.

You code, therefore, should look like this:


  let print_logic a b =
    Printf.printf "a and b is %B\n" (a && b);
    Printf.printf "a or b is %B\n" (a || b);
    Printf.printf "not a is %B\n" (not a)
  ;;

  print_logic true false;;


Peng

On Monday 04 August 2008 02:32:36 pm Ben Aurel wrote:
> hi
> yeah - the question is low, but I-m struggling on different frontiers
>
> /////////////// print_logic.ml ///////////////////////////////
> ````````````````````````````````````````
> 1 let print_logic a b =
> 2 Printf.printf "a and b is %B\n" (a && b);
> 3 Printf.printf "a or b is %B\n" (a || b);
> 4 Printf.printf "not a is %B\n" (not a)    (* Q1 *)
> 5
> 6 print_logic(true, false);; (* Q2 *)
>
> ```````````````````````````````````````
>
> Problem: the code doesn't compile and I don't find any help on the web.
>
> Questions:
>  (* Q1 *): Somehow I don't get the concept with ";" and ";;". On line
> 4 do I need to end the statement with semicolon double-semicolon or
> nothing?
>
>  (* Q2 *): How can I pass those parameters?
>
>
> Maybe there is something that's else wrong.
>
> thanks
> ben
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFImFUBfIRcEFL/JewRAuRvAJ4yXnpbBE6wQzBlg66hClZomYWBPACfUabY
rHz86mdOg5FIaSk/bi5O9aE=
=L61/
-----END PGP SIGNATURE-----


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

end of thread, other threads:[~2008-08-05 13:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-04 18:32 newbie: how to call a function with multiple parameters? Ben Aurel
2008-08-05 11:40 ` [Caml-list] " asmadeus77
2008-08-05 11:46 ` micha
2008-08-05 13:26 ` Peng Zang

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