3 ms·
One really nice feature from Wolfram Mathematica that few other languages seem to have is a special prefix-only syntax for single-argument function application.
by HALtheWise 6y ago
One really nice feature from Wolfram Mathematica that few other languages seem to have is a special prefix-only syntax for single-argument function application. In Mathematica, it's f@x ==> f(x), and it's really convenient because it prevents needing to move your cursor to the end to put in a closing paren. Since it only works for single-argument functions, there's no ambiguity.
- tzot 6y agoIn any case, this can be done now with a helper class used as a decorator. >>> class At: __slots__= 'fun', def __init__(self, fun): self.fun = fun def __matmul__(self, arg): return self.fun(arg) def __call__(self, *args, **kwargs): return self.fun(*args, **kwargs) >>> @At def square(x): return x*x >>> square(2) 4 >>> square@2 4
- jfkebwjsbx 6y agoThere is nothing nice about it. Not even in a REPL. Preventing a simple move of the cursor does not justify complexity and yet another way to apply a function.