I am currently looking for a programming language to write a math class in. I know that there are lots and lots of them everywhere around, but since I'm going to start studying math next semester, I thought this might be a good way to get a deeper insight in to what I've learned.
Thanks for your replys.
BTW: If you are wondering what I wanted to ask:
"Is there a strongly typed programming language which allows you to define new operators?"
A strongly typed programming language is one in which each type of data, such as integers, characters, hexadecimals and packed decimals, is predefined as part of the programming language, and all constants or variables defined for a given program must be described with one of the data types.
Smalltalk, Ruby, Python, and Self are all "strongly typed" in the sense that typing errors are prevented at runtime and they do little implicit type conversion, but these languages make no use of static type checking: the compiler does not check or enforce type constraint rules.
C is statically but weakly typed: The weakly type system allows some freedom for speed improvements and allows to handle the memory at a low level. It is thus perfectly fine to use it when you know what you are doing, for tasks where the memory footprint and speed are important.
Python is both a strongly typed and a dynamically typed language. Strong typing means that variables do have a type and that the type matters when performing operations on a variable. Dynamic typing means that the type of the variable is determined only during runtime.
Like EFraim said, Haskell makes this pretty easy:
% ghci ghci> let a *-* b = (a*a) - (b*b) ghci> :type (*-*) (*-*) :: (Num a) => a -> a -> a ghci> 4 *-* 3 7 ghci> 1.2 *-* 0.9 0.6299999999999999 ghci> (*-*) 5 3 16 ghci> :{ let gcd a b | a > b = gcd (a - b) b | b > a = gcd a (b - a) | otherwise = a :} ghci> :type gcd gcd :: (Ord a, Num a) => a -> a -> a ghci> gcd 3 6 3 ghci> gcd 12 11 1 ghci> 18 `gcd` 12 6
You can define new infix operators (symbols only) using an infix syntax. You can then use them as infix operators, or enclose them in parens to use them as a normal function.
You can also use normal functions (letters, numbers, underscores and single-quotes) as operators by enclosing them in backticks.
Well, you can redefine a fixed set of operators in many languages, like C++ or C#. Others, like F# or Scala allow you to define even new operators (even as infix ones) which might be even nicer for math-y stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With