caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain.frisch@lexifi.com>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: Helmut Brandl <helmut.brandl@gmx.net>, caml-list@inria.fr
Subject: Re: [Caml-list] js_of_ocaml with node
Date: Tue, 28 Apr 2015 10:11:24 +0200	[thread overview]
Message-ID: <553F40AC.3040202@lexifi.com> (raw)
In-Reply-To: <553F3C86.4060809@frisch.fr>

On 04/28/2015 09:53 AM, Alain Frisch wrote:
> val mkdir_async:
>      string ->
>      ?mode:(int[@js.default 0o777]) ->
>      (js_exn option -> unit) ->
>      unit
>    [@@js.global "fs.mkdir"]
>
>
> Here js.default forces the default value for the optional mode argument.
>   Without it, a missing value will send an `undefined` as the second
> argument (I don't know if fs.mkdir would be happy with it).

Just to clarify:  the issue here is that node.js documents the function as:

  fs.mkdir(path[, mode], callback)


and its implementation is more liberal:

=================
function modeNum(m, def) {
   if (util.isNumber(m))
     return m;
   if (util.isString(m))
     return parseInt(m, 8);
   if (def)
     return modeNum(def);
   return undefined;
}

fs.mkdir = function(path, mode, callback) {
   if (util.isFunction(mode)) callback = mode;
   ...
       modeNum(mode, 511 /*=0777*/)
   ...
};
=================

(welcome to Javascript wonderful calling conventions!)


So both conventions are supported to omit the mode argument:

   fs.mkdir(path, undefined, callback)
   fs.mkdir(path, callback)


(one could actually pass anything as the second argument as long as it 
is not a number, not a string and not a function).

So it is ok to bind it simply as:

val mkdir_async: string -> ?mode:int -> (js_exn option -> unit) ->  unit
   [@@js.global "fs.mkdir"]



Alain

  reply	other threads:[~2015-04-28  8:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 20:32 Helmut Brandl
2015-04-27 21:02 ` Sébastien Dailly
2015-04-27 21:16   ` Helmut Brandl
2015-04-28  7:08     ` Sébastien Dailly
2015-04-27 21:11 ` Daniel Bünzli
2015-04-27 22:03 ` Alain Frisch
2015-04-27 22:41   ` Daniel Bünzli
2015-04-28  7:53     ` Alain Frisch
2015-04-28  8:11       ` Alain Frisch [this message]
2015-04-28 11:17       ` Drup
2015-04-29 22:03         ` Helmut Brandl
2015-04-29 22:49           ` Mauricio Fernández

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=553F40AC.3040202@lexifi.com \
    --to=alain.frisch@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@erratique.ch \
    --cc=helmut.brandl@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).