-2
$\begingroup$

Consider two functions, f and g. f is a curried function. It takes a single argument and returns another function. It seems that f and g are similar. However, their behaviours are quite different.

I want to know the practical use of g[x][y][z], and under what circumstances I should use it.

In:

Clear[f, g]
f[x_] := y \[Function] z \[Function] x + y + z
f[x]
f[x][y]
f[x][y][z]

g[x_][y_][z_] := x + y + z
g[x]
g[x][y]
g[x][y][z]

Out:

Function[y$, Function[z$, x + y$ + z$]]
Function[z$, x + y + z$]
x + y + z

g[x]
g[x][y]
x + y + z

Derivative is like g. It isn't a typical example. I guess most of people use the operator ('), but not the general form Derivative[n1,n2,...][f].

This question is inspired by the snippet of ClangCompiler.m.

ClangCompiler[method_][args___] := 
  CCompilerDriver`CCompilerDriverBase`BaseDriver[method][args]

After I went through CCompilierDriverBase.m, it seems that this form is like an association.

BaseDriver["OptionsExceptions"]["CreateLibrary"] := {"MprepOptions"}

BaseDriver["OptionsExceptions"]["CreateExecutable"] := {"LibraryType"}

BaseDriver["OptionsExceptions"]["CreateObjectFile"] := 
  {"ExtraObjectFiles", "Libraries", "LibraryType", "LinkerOptions", 
   "MprepOptions", "SystemLibraries", "SystemLinkerOptions"}
$\endgroup$
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$ – Kuba May 30 '17 at 18:31
0
$\begingroup$

This started out as another comment, but I turned it into an attempted answer.

If I interpret the question as "what can g-type functions do that f-type can't", I think it's similar to asking why one would want to use SetDelayed rather than Set together with Function. You can a lot of things with h=Function[...], but it can still be more elegant/useful to use h[...]:=.... Then there are things like foo[x_EvenQ]:=bar[x] that leave foo[3] unevaluated. It's also easier to add more definitions later with SetDelayed.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.