4 ms·
In CL, slots are named by a symbol, and anyone can access it if they have access to the symbol. Symbols however are, by default, internal to a package (~namespa
by juki 5y ago
In CL, slots are named by a symbol, and anyone can access it if they have access to the symbol. Symbols however are, by default, internal to a package (~namespace). Internal symbols won't be included when someone imports the package to another one. They can still be used from outside the package, but it requires explicitly using the double-colon `package::symbol`-syntax.
- galaxyLogic 5y agoSo what do you have outside the module that allows you to get or set the value of a slot? A function per slot written inside the module that owns the symbols? I know that in JavaScript ES6 you can define symbols that are private to the module which defines them which can effectively encapsulate data inside object-instances. That works best with an ES6 classes which have methods which are public but which can then access the data via those module-private symbols.
- juki 5y ago> A function per slot written inside the module that owns the symbols? Yes, usually you define accessors/readers for the slots that you want to be available to others. An accessor is basically a function that can be used like a variable, but allows arbitrary code to run when getting/setting it (this is important to allow macros to be written without having to constantly worry about whether something is a function call or a variable). The `defclass` macro has an option to automatically generate accessors, readers or writers for the simple case (just directly reading/writing the slot), but you can also define more complex ones by hand. You could of course also export the symbol to allow direct access to the slot, but accessors are the typical choice.