empirical-lang icon indicating copy to clipboard operation
empirical-lang copied to clipboard

Generic form of print() / String() / repr()

Open chrisaycock opened this issue 4 years ago • 2 comments

We currently can't use print() on Dataframes. The reason is that VVM's print is overloaded to builtin types, which was necessary in the dark ages of Empirical (ie., last week). With metaprogramming, we can now solve this problem and a few others.

Start with these generic definitions:

func repr(x) => _repr(x, type_of(x))

func String(x) => repr(x)

func print(x) => _print(String(x))

This keeps repr as is; the default String() cast invokes that repr. VVM will then specialize the cast with its own routines. Users can also create their own specializations for one or both of these functions.

This requires two changes:

  1. Specialization of generic functions -- see #56
  2. Move the repr/save logic from Codegen to Sema

chrisaycock avatar Aug 19 '20 13:08 chrisaycock

CC @andrewnc

chrisaycock avatar Aug 19 '20 13:08 chrisaycock

Probably should tackle #43 before adding generic repr() since the save() logic will have to go into Sema.

chrisaycock avatar Aug 21 '20 20:08 chrisaycock