4 ms·
No. All languages are typed in one way or another. Unless you write a generic function, you cannot evaluate (+ 2 "a") in scheme. Here is racket's error message
by tpfour 7y ago
No.
All languages are typed in one way or another. Unless you write a generic function, you cannot evaluate (+ 2 "a") in scheme. Here is racket's error message:
> (+ 2 "a")
; +: contract violation
; expected: number?
; given: "a"
; argument position: 2nd
; [,bt for context]
>
The function absolutely expects its arguments to have a certain shape (type). The difference with C is that variables don't have types set in stone, they can... vary. The compiler/interpreter just takes care of them for you.
- chii 7y agoBut you cannot tell ahead of time that you cannot evaluate (+ 2 "a"). If the code wasn't so obvious as the above example, you'd have a hard time mentally working out the correctness. E.g., given both (shoot camera person) and (shoot gun dummy), you'd not want to accidentally pass in the wrong arguments like (shoot gun person).