You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A possible way to support standalone Coalton files is to extend the existing 'package' declaration to refer to symbols in dependencies and specify exports, and use the parsed declaration to maintain underlying Common Lisp packages. Having a limited, fixed-position, "file header" declaration may allow for automated dependency and compile order calculation, and simplify editor integration. Here is a proposed syntax:
The package form must be the first form in a file.
Evaluating a package form replaces any previous package definition with the same name. This replacement happens at compile time.
The import clause is the means for referring to other packages. Each import can be either:
A package name, to import all symbols from a package, or
The list (PACKAGENAME SYM_1 ... SYM_n) to import specific symbols.
The export clause specifies which functions, types, variables, etc. are exported, and works just like Lisp.
The nickname clause provides a way to refer to symbols in other packages using short prefixes. Each nickname entry is a two-element list (PACKAGENAME NICKNAME), where PACKAGENAME is the full package name and NICKNAME is the prefix.
All clauses appearing after the package name are optional, and can be omitted or repeated, in any order.
Package names, symbols, and nicknames are case-insensitive strings.
The compiler resolves imports, exports, and nicknames at parse time or immediately thereafter.
The imported symbols and nicknames are visible to embedded Lisp.
Implementation
Extend parser to recognize the new package form
support direct package creation/modification
generation of underlying Lisp defpackage form
add file-oriented compiler entry point
add asdf .coalton file compile and load operations
Questions
When compiling a Coalton file, the package is created immediately during parsing. Any concern about side-effecting here, if the rest of the compilation fails?
Are bare strings/identifiers acceptable for everything in the package form? Or should there be some distinguishing syntax (like the #: in lisp)? Bare strings seem most concise.
import/export are more "pythonic" than "lispy" but on the other hand seem very clear and simple. Is this a good choice?
About your question 1 above, it might be worthwhile to supply package superseding and deletion control in the package definition form itself. It would be handy if, when provided the right option, the define package will unintern all symbols in the defined package so that Lisp won't complain about missing exports when they've been removed. Similarly, a package deletion option could be included to outright drop a package on compilation errors if that is something that ever needs to happen. I am having a hard time imagining a circumstance where you'd want to delete a package rather than just specify that a new definition supersede an old one, but it could come up.
bare strings could be enough. I want to know if the system you have in mind distinguishes between internal and external symbols. For example ould ("mypackage" "foo1") only import mypackage:foo1 or would it grab mypackage::foo1 (assuming foo1 is not exported from mypackage)?
I think we should spell out that this form would work best with a one-package-per file approach. And in that case, I think it is worthwhile to think more seriously about inferring package name from file name. And if we do that, then we can probably do something "flatter" with imports and exports - perhaps touching on your question 3 above.
For 1, there is also package locking. Maybe something like a (pragma {lock replace ... }) clause could cover options like those.
To 2, I was assuming external symbols, so that, in the style where ':' and '::' prefixed symbols are avoided in the body of code, someone could resolve clashing global imports. Internal symbols could always be reached with fully qualified (or nicknamed) symbols.
Inferring package name is definitely possible, and could coexist with the (package ...) version described here. Any (import | export | nickname | pragma ...) form could be read off the top of the file and combined with path information. There would be more behavior to specify, like, how are directories and subdirectories interpreted, if at all?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
A possible way to support standalone Coalton files is to extend the existing 'package' declaration to refer to symbols in dependencies and specify exports, and use the parsed declaration to maintain underlying Common Lisp packages. Having a limited, fixed-position, "file header" declaration may allow for automated dependency and compile order calculation, and simplify editor integration. Here is a proposed syntax:
The
package
form must be the first form in a file.Evaluating a
package
form replaces any previous package definition with the same name. This replacement happens at compile time.The
import
clause is the means for referring to other packages. Each import can be either:(PACKAGENAME SYM_1 ... SYM_n)
to import specific symbols.The
export
clause specifies which functions, types, variables, etc. are exported, and works just like Lisp.The
nickname
clause provides a way to refer to symbols in other packages using short prefixes. Each nickname entry is a two-element list(PACKAGENAME NICKNAME)
, wherePACKAGENAME
is the full package name andNICKNAME
is the prefix.All clauses appearing after the package name are optional, and can be omitted or repeated, in any order.
Package names, symbols, and nicknames are case-insensitive strings.
The compiler resolves imports, exports, and nicknames at parse time or immediately thereafter.
The imported symbols and nicknames are visible to embedded Lisp.
Implementation
Questions
Beta Was this translation helpful? Give feedback.
All reactions