4 ms·
It might be from me being so used to it, but I do like Elixir’s `def`/`defp` second best to Rust’s `pub`
by kzemek 1y ago
It might be from me being so used to it, but I do like Elixir’s `def`/`defp` second best to Rust’s `pub`
- nagaiaida 1y agopersonally, i like that raku goes the other way, with exported bits of the interface explicitly tagged using `is export` (which also allows for the creation of selectably importable subsets of the module through keyed export/import with `is export(:batteries)`/`use TheModule :batteries`, e.g. for a more featureful interface with a cost not every user of the module wants to pay). it feels more natural to me to explicitly manage what gets exported and how at a different level than the keyword used to define something. i don't dislike rust's solution per se, but if you're someone like me who still instinctually does start-of-line relative searches for definitions, suddenly `fn` and `pub fn` are separate namespaces (possibly without clear indication which has the definition i'm looking for)
- lizmat 1y agoActually, a module can implement any export heuristics by supplying an EXPORT subroutine, which takes positional arguments from the `use` statement, and is expected to return a Map with the items that should be exported. For example: sub EXPORT() { Map.new: "&frobnicate" => &sum } would import the core's "sum" routine, but call it "frobnicate" in the imported scope. Note that the EXPORT sub can also be a multi, if you'd like different behaviour for different arguments.
- nagaiaida 1y agoneat! i've never needed more than i could get away with by just sneaking the base stuff into the mandatory exports and keying the rest off a single arg, but that'll be handy when i do.