3 ms·
Both Python and Lua share this characteristic with Javascript. Is there a name for this language feature, or for languages that share it? I tend to think of t
by shubber 16y ago
Both Python and Lua share this characteristic with Javascript. Is there a name for this language feature, or for languages that share it?
I tend to think of them as "bag-of-things" languages, since they also all share the fact that objects are just tables/dictionaries, and the only thing that distinguishes an attribute reference from a method call is the "()" at the end. Certainly there's a more accepted nomenclature?
- silentbicycle 16y ago> Certainly there's a more accepted nomenclature? I don't know if there is, but there should be. The defining aspect seems to be that there aren't pure ADTs, just collections based an associative arrays ("dicts" / "tables"), and methods are just table fields that contain a function. Also, Python has classes where Lua really does just have pure tables with hooks ("metatables", which make it easy to implement prototypes, classes, and many other constructs).
- cheald 16y agoWhat you're terming "bag-of-things" languages can probably be more aptly described as languages which have both dict/tables/objects and first-class functions. While there isn't really a term (that I'm aware of) specifically for the this/self convention, both are idiomatic examples of dynamic scoping (compared to lexical scoping); that is, scope is determined at runtime by the most recent stack frame to define a given variable (ie, foo defines "this", then calls "bar", bar sees "this" as it was defined by foo), rather than at lex time.
- shubber 16y agoWhile there's a correlation between dynamic scoping and explicit "this", it isn't universal: Ruby being the obvious exception.