Access Control Syntax
journal.stuffwithstuff.com
journal.stuffwithstuff.com
pub status "#blah"
pub struct foo(etc etc)
pri func foo.bar(etc etc)
Since code is also auto-formatted, you can do things like "show me a structural overview of a package's source code" with a simple grep: rg -N ^p std/jpeg/*.wuffs
If you want just the exported API, change p to pub: rg -N ^pub std/jpeg/*.wuffs> If a class member starts with two leading underscores, then it really is private. The language will name mangle it to make it inaccessible.
$ cat > jimbo.py <<PY
__to_whom__ = "world"
def __hello():
return __to_whom__
PY
python3 -c '
import jimbo
print(dir(jimbo))
print(jimbo.__to_whom__)
'
['__builtins__', '__cached__', '__doc__', '__file__', '__hello', '__loader__', '__name__', '__package__', '__spec__', '__to_whom__']
world
and, just on the off chance they really meant "class member" I tried that, too $ cat jimbo.py; python3 -c 'import jimbo
print(dir(jimbo.s))
print(jimbo.s.__to_whom__)
'
class Sekrit:
__to_whom__ = "world"
def __hello(self):
return self.__to_whom__
s = Sekrit()
['_Sekrit__hello', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '__to_whom__', '__weakref__']
worldI guess this could qualify for a TIL because I didn't know Python treated leading and trailing dunders any different and that they were its implementation of "protected" and "private" only by convention
Members ending in a double underscore as well aren't mangled, because this interferes with syntax sugar methods like __add__ (addition operator overloading).
For the longest time, I believed that this was dumb, and that the default should’ve been private. Over time, my style has changed a fair bit, and these days I tend to think of packages, rather than classes, as the more important unit of code, and I find that package private was probably the right choice.
The main other language feature it interacts with is types. And with compile-time type checking. Especially in the "separate compilation" scenario. Especially in the "incremental compilation" scenario. It was a hot research topic back in the 90s, culminating with SML's idea of translucent modules. It's still a research topic today.
Exporting/importing values and variables, on the other hand, is entirely straightforward in comparison. The only thing you really have to think about is whether "const" means "constant during one program execution" (i.e. whether doing "x := 3" is legal or not) or "constant during the whole development cycle" (i.e. whether you can inline it's current declared value into the places where it's used or not).
``` <~ foo := (a: int) { a - 1 } ```
Then at the import site:
``` ~> foo ```
* some day it’ll totally for real make it off the page and into an interpreter I’m sure :,)
-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.
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)
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.
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.
Names visible outside their scope begin with a dot.
foo = {
a = 3;
.b = a + 1;
};
print(foo.a) // error
print(foo.b) // '4' class A {
public:
int a;
float b;
private:
...
};