Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.

RFC: Module definition language #20

@hellerve

Description

@hellerve

Writing modules is an essential part of organizing zepto code. However, modules soon get cluttered.

This RFC proposes a language for structuring modules by files. I believe it is best if we look at the old way of defining modules and a proposed syntactic alternative side by side.

(module "example"
   (export
      `("exp-fn" fn)
      `("fn2" fn2))

   (internal (lambda (x) (write x)))

   (fn (lambda (x) (internal x)))
   (fn2 (lambda () (internal 1))))

This is fairly contrived, but relatively simple. It defined three functions internal, fn, and fn2 and exports the latter two as exp-fn and fn2, respectively.

Leveraging the proposed language, that action would look like this:

#lang module example

(export
   fn2
   [fn :as exp-fn])

(define (internal x)
   (write x))
; or even: (define internal write)

(define (fn x)
   (internal x))
; or even: (define fn internal)

(define (fn2)
   (internal 1))
; or even: (define fn2 (curry internal 1))

To me, that looks cleaner, simpler, and less cluttered. It also has the advantage that module extension could be simplified by detecting at load time whether the module should be created or extended instead of doing it explicitly through module-extend.

The syntax can be toyed around with and changed until we reach consensus reality.

Cheers

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions