5 ms·
I like the final approach. What about -def sayHi() Or def- sayHi() I feel like having a minus communicates the intend of taking the declaration out of the p
by metayrnc 1y ago
I like the final approach. What about
-def sayHi()
Or
def- sayHi()
I feel like having a minus communicates the intend of taking the declaration out of the public exports of a module.
- munificent 1y agoThat's clever way to think of "-". :) I'll think about that.
- kzemek 1y agoIt 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.
- amonks 1y agoThere's some prior art here from Clojure, where defn- creates private definitions and defn public ones: https://clojuredocs.org/clojure.core/defn- https://clojuredocs.org/clojure.core/defn- In Clojure this isn't syntax per-se: defn- and defn are both normal identifiers and are defined in the standard library, but, still, I think it's useful precedent for helping us understand how other people have thought about the minus character.