Table of Contents for Programming Languages: a survey
on a traditional american keyboard, many unshifted punctuation characters have obvious arithmetic meanings (+,-*,/,^,=). should a language stick with these, or use those for something more common and use other things for arithmetic?
quite useful for nested grouping
see also http://en.wikipedia.org/wiki/Bracket#Computing
/\, <>, [], {}, () any others in ASCII?
e.g. instead of ';' in C
need a way to replace any function using EOLs. usually semicolons for EOL and braces for grouping blocks.
some languages e.g. Python don't support one-liners. other languages e.g. haskell support both a significant whitespace mode (haskell calls this 'layout') and one-liners
..and lambdas
need to separate arguments from each other, and all arguments from function body
some languages (e.g. MATLAB) also define return values
tuples
f() or prefix or haskell
fixed or custom
infixify a prefix op
section an infix operator to get a prefix function
traditional precedence table
todo; but *,/ > +,0 > comparisons > boolean ops
if too many levels, programmers can't make us of it anyway because they can't remember the precedence and it's easier to use parens than to look it up; but they will still pay a price when they see someone else's code without parens and they must look it up to parse it custom precedence is perhaps an extreme version of this
if too few levels, programmers must use lots of parens extreme version of this: no infix e.g. lisp
currying
and variadic keywords
like C's #ifdef, Nimrod's "when" http://nimrod-code.org/tut1.html#when-statement
e.g. 'x = 3' instead of '(let x 3)
an l-value is the thing on the left of the equals sign in an assignment statements using 'a = b' syntax. e.g. in 'x = 3', the l-value is 'x'.
A complex l-value is when a location must be resolved instead of being immediately given, e.g. "x[2] = 3"
a similar thing is how in Common Lisp you can do (assuming 'behavior' is a property list, that is, a dict/map/hash):
" (setf (get ’dog ’behavior)
here, instead of resolving (get ’dog ’behavior) to a value immediately, setf takes the LOCATION being read by (get ’dog ’behavior), and then assigns to that location.
in C, mostly undefined, except for short-circuit operators
e.g. in C code like "a = b() + c()" can call b() and c() in any order. If they have side effects then this might matter, yet no compiler error is given. However, the evaluation order of a() && b() IS specified.
e.g. in bash, $0 is the name of the current script, $1 is the first positional parameter that was passed in, $2 is the second positional parameter, etc
in some languages a similar scheme for special variables for positional parameters is at the function level
e.g. ruby: ruby blocks
e.g. Apple Swift: blocks e.g. "let sortedCities = sort(cities) { $0 < $1 }"
e.g. Objective C: http://arstechnica.com/apple/2009/08/mac-os-x-10-6/10/#blocks
(note: goes well with implicit parameter special variable names)
e.g. in C
http://stackoverflow.com/questions/151850/why-would-you-use-an-assignment-in-a-condition
however this can cause confusion between = and ==:
e.g. in Apple Swift:
" if let indexOfLondon = find(sortedCities, "London") { println("London is city number \(indexOfLondon + 1) in the list") } "
e.g. "print 'big' if x > 3"
some choices:
"constructor syntax": e.g. String(2) == "2"
"conversion function syntax": conv(2, Int, String)
"generic conversion-to function syntax": conv(2, String)
no syntax, and conversion functions: intToString(2)
no syntax, and generic conversion-to functions: toString(2)
no syntax, and generic conversion-from functions: fromInt(2) :: String (note: in languages with type inference the destination type may be inferred instead of annotated, making this skirt the line between implicit and explicit)
note: the following is actually implicit, not explicit: "annotation syntax": 2 :: String