2 ms·
> Do they have in-memory data structures with attached functions What do you mean by "attached function"?
by tome 9y ago
> Do they have in-memory data structures with attached functions
What do you mean by "attached function"?
- jcelerier 9y agoI meant that a semantic value in the code (a variable for instance) "carries" functions with it, as methods. e.g. in a C API: struct foo { // dispatch void (*do_stuff)(int); int (*get_stuff)(const char*, void* context); }; // attached functions void foo_do_operation1(foo*); int foo_do_operation2(foo*, int); or C++ which allow to conflate both forms but restricts the first with inheritance struct foo { virtual void do_stuff() = 0; virtual int get_stuff(std::string, a_better_type_than_void_ptr&) = 0; void do_operation1(); int do_operation2(int); }; or JS where everything can change whether you want it or not var v = new Object; v.do_stuff = function() { ... } v.get_stuff = function(str, something) { ... } v.do_operation1 = function() { /* v is available in the closure */ } etc... or OCaml modules: module foo = struct let do_operation1 = ... let do_operation2 x = ... end in every case, some state is mentioned first, and then some code is bound to this state; then, the language (except in C where it is only a convention... even though some people can get fairly "creative" with macros) provides a way to call the code with a given variable of type `foo`.