Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a compiled* programming language with dynamic, maybe even weak typing?

I wondered if there is a programming language which compiles to machine code/binary (not bytecode then executed by a VM, that's something completely different when considering typing) that features dynamic and/or weak typing, e.g:

Think of a compiled language where:

  • Variables don't need to be declared
  • Variables can be created during runtime
  • Functions can return values of different types

Questions:

  • Is there such a programming language?
  • (Why) not?

I think that a dynamically yet strong typed, compiled language would really sense, but is it possible?

like image 986
sub Avatar asked Mar 31 '10 17:03

sub


People also ask

Can a compiled language have dynamic typing?

No - it's certainly possible to compile dynamic languages. There are even some dynamic languages that are always compiled by design (e.g. Clojure).

What programming language that is dynamic in typing?

In dynamic typing, types are associated with values not variables. Dynamically typed languages include Groovy, JavaScript, Lisp, Lua, Objective-C, Perl (with respect to user-defined types but not built-in types), PHP, Prolog, Python, Ruby, Smalltalk and Tcl.

Is dynamic typing the same thing as weak typing?

So in simple terms, static/dynamic typing refers to the time when type checking occurs: compile time for static typing, and run time for dynamic languages. Likewise, strong/weak typing refers to how aggressive a language is in enforcing its type system.

What programming languages are weakly typed?

Weak Typing For instance, JavaScript is an example of weakly typed language. The implication is that operations between variables of different data types are legal.


2 Answers

I believe Lisp fits that description.

http://en.wikipedia.org/wiki/Common_Lisp

like image 85
Stephen Avatar answered Sep 21 '22 11:09

Stephen


Objective-C might have some of the properties you seek. Classes can be opened and altered in runtime, and you can send any kind of message to an object, whether it usually responds to it or not. In that way, you can implement duck typing, much like in Ruby. The type id, roughly equivalent to a void*, can be endowed with interfaces that specify a contract that the (otherwise unknown) type will adhere to.

like image 23
Jakob Borg Avatar answered Sep 21 '22 11:09

Jakob Borg