[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: another take on hackers and painters



> Are there any statically typed languages that expose an interface like
> Scheme's eval or Python's exec/eval (which actually take strings)?[1]  If
> so, what does the interface look like?[2]

The Curl language has a hybrid static/dynamic typing system and has an
'evaluate' function with the signature:

   {evaluate expression:any}:any

where 'expression' must be a StringInterface, a CurlSource or a Url (in which
case the source is read from the URL).  [Actually, 'evaluate' has two optional
keyword arguments not shown here.] The 'any' type is the supertype of all other
types and variables declared with this type do runtime type checks, method
dispatches etc; variables declared with other types require static checks.

For example, given the classes:

  {define-class A {method {a}:void}
  {define-class B {inherits A} {method {b}:void}}

and the function:

  {define-proc {make-A}:A {return {B}}}

you could use an 'any' to do runtime dispatching:

  let x:any = {make-A}
  {x.b}

or you could use an explicit cast:

  let x:B = {make-A} asa B
  {x.b}

or you could use a type-switch:

  let x:A = {make-A}
  || {x.b} here would produce a compile-time error
  {type-switch x
   case x:B do
     {x.b}
   case x:A do
      ...
   }

This allows the developer to choose on a case-by-case basis between the
flexibility of dynamic type-checking and dispatch and the speed and compile-time
checking of static checking.  They can also restrict the use of runtime casts
and dispatch through 'any' variables using in-source compiler directives.

- Christopher