3 ms·
>Why does '+' (and friends) get this special form, but not my functions? Your functions can get that (and other) special form. You need to use a language where
by jsprogrammer 11y ago
>Why does '+' (and friends) get this special form, but not my functions?
Your functions can get that (and other) special form. You need to use a language where you can define your own operators. Have you looked at C++, C#, Haskell, or LISP?
- JoeAltmaier 11y agoHuh. C++? You can overload operators, but define your own? I must have missed something.
- janvidar 11y agoWell, I suppose you can #define your own?
- winter_blue 11y ago#define function(arg1, arg2, arg3) exists for creating macro functions, but nothing exists for naturally creating macro unary or binary operators in C and its descendants.
- jsprogrammer 11y agoEach language will have a different meaning of what exactly it means to "define your own". C++ restricts which symbols may be operators, but, you can "define your own +".
- kibwen 11y agoIn practice it's very useful to distinguish between a language which "just" has operator overloading vs a language that allows custom user-defined symbolic operators. The existence of the latter is actually one of the few complaints that I have about Swift so far, but I'm sure many people will ardently disagree with me here. :P
- Retra 11y agoIt's a wonderful feature for writing DSLs, but it's also confusing when you intermingle DSLs with the standard language. It really tends to balloon the amount of information you need to know to read others' code.
- dragonwriter 11y ago> Your functions can get that (and other) special form. You need to use a language where you can define your own operators. Have you looked at C++, C#, Haskell, or LISP? AFAIK, Lisp doesn't have syntactically-distinct operators at all just functions which may have names similar to operators used in other languages, and C# and C++ don't seem to support custom operators at all. [0] OTOH, Perl 6 has robust support for custom operators. [0] except that C++ has apparently been hacked to create custom operators with some limitations via macros [1] [1] http://www.codeproject.com/Articles/31783/Custom-User-Defined-Operators-in-C http://www.codeproject.com/Articles/31783/Custom-User-Define...
- jsprogrammer 11y agoWhat "operator" means will be language dependent. An operator is fundamentally just a function, so LISP fits.
- ryanschneider 11y ago> You need to use a language where you can define your own operators. Have you looked at C++, C#, Haskell, or LISP? Or, um, Swift. :) http://nshipster.com/swift-operators/ http://nshipster.com/swift-operators/
- chrislattner 11y agoMore directly, check out: https://github.com/apple/swift/blob/master/stdlib/public/core/Policy.swift https://github.com/apple/swift/blob/master/stdlib/public/cor... Which is where much of the Swift "language" is defined... in the standard library. -Chris