Short forum post on REST API

Adam D. Ruppe destructionator at gmail.com
Sun Apr 17 18:45:27 PDT 2011


Wow... actually, the names aren't always right, including in the
example.

I used a ParameterNamesOf!(), written by a newsgroup member a while
ago (I don't remember who), which cleverly uses typeof().stringof
and parses it to extract parameter names.

Strangely though, dmd seems to use the parameter names off the first
function of that type it sees.

Here, "int num" was first, so it used int num everywhere. If you
switch the second function "int wat" to the first position, dmd
gives that for both of them!


Of course, it works because the program uses the same method
to generate the code as to parse it. It's all consistent so it
works. My PHP based external caller uses positional parameters,
so it doesn't matter either. Only if you were to manually type
the argument names would you notice something fail.

But, I used the arg name for error messages and generated forms,
so it might be  noticeable there - it won't necessarily match up
with the documentation.

Blargh. But hey, it all works anyway! And if your signatures aren't
the same, the names work too. Even if they didn't work at all
though, this is still pretty win, especially if the D functions
return DOM elements!

Still to come: use D's reflection to give more behavior to pure
functions. Memoizing them (that is, using the HTTP cache
automatically) could give a huge benefit here.


More information about the Digitalmars-d-announce mailing list