6 ms·
The dynamic typing example doesn't have anything to do with dynamic typing and is in fact already a feature of some statically-typed programming languages.
by PhineasRex 4y ago
The dynamic typing example doesn't have anything to do with dynamic typing and is in fact already a feature of some statically-typed programming languages.
- brabel 4y agoCommon Lisp can do that: CL-USER> (defvar i 1) I CL-USER> (declaim (type (integer 1 10) i)) (I) CL-USER> i 1 CL-USER> (setf i 8) 8 CL-USER> i 8 CL-USER> (setf i (1+ i)) 9 CL-USER> (setf i (1+ i)) 10 CL-USER> (setf i (1+ i)) ; Evaluation aborted on #<TYPE-ERROR expected-type: (INTEGER 1 10) datum: 11>. CL-USER> i 10
- em-bee 4y agoin pike: #pragma strict_types void main() { int(1..10) i = 3; i += 7; i += 1; write("%O\n", i); i = 11; } output: typetest.pike:6: Warning: An expression of type int cannot be assigned to a variable of type int(1..10). typetest.pike:8:Bad type in assignment. typetest.pike:8:Expected: int(1..10). typetest.pike:8:Got : int(11..11). Pike: Failed to compile script.