liquidsoap icon indicating copy to clipboard operation
liquidsoap copied to clipboard

POC: import/export.

Open toots opened this issue 1 year ago • 2 comments

This is a first stab at a proper module import/export.

Syntax:

Export "module.liq"

let export foo = "123"
def export bla() =
  print("bla")
end

Import:

let import { foo, bla } = "module.liq"

The implementation works by replacing "module.liq" in the import statement with the type-checked term:

let _export_ = ()

let _export_.foo = "123"

def _export_.bla() =
  print("bla")
end

_export_

Based on this, it should be possible to cache the result of the evaluation of "module.liq" to speed up future executions.

toots avatar Jun 02 '23 03:06 toots

A general remark: adding export everywhere is very cumbersome. I'd rather have everything exported by default and have a private keyword for non-exported values.

smimram avatar Jun 02 '23 13:06 smimram

A general remark: adding export everywhere is very cumbersome. I'd rather have everything exported by default and have a private keyword for non-exported values.

I'll think about it but there are a couple of reasons I could see against it:

  • This means the export stuff would be everywhere in all file parsed, not just those intended to be a module
  • The pattern of explicit export is more common than implicit export. It is also easier to proof read if there's ever an issue with an export
  • We accept variable override by default but I think (not implemented) that we should actually refuse multiple export with the same name as it is hard to proof read/debug.
  • Eventually, it'd be nice to be able to do some dead code elimination. Promoting an explicit export pattern would make this more efficient as well.

toots avatar Jun 02 '23 16:06 toots