6 ms·
> But that's not the composition that I'm talking about. Okay, then: composeObjects(first, second) = { third = new Object third._methods = fir
by yellowapple 7y ago
> But that's not the composition that I'm talking about.
Okay, then:
composeObjects(first, second) = {
third = new Object
third._methods = first._methods.merge(second._methods)
return third
}
class Foo { hi = { puts "howdy" } }
class Bar { bye = { puts "adios" } }
baz = composeObjects(new Foo, new Bar)
baz.hi # prints "howdy"
baz.bye # prints "adios"
Tada!
This is only slightly simplified from languages like, say, Ruby or Common Lisp, both of which (last I checked) support this sort of class-oriented metaprogramming (or Perl, which exposes the ability to "bless" arbitrary data structures as objects).
> But like your example shows, it is awkward.
In what way was that especially awkward? You take two pointers to already-compiled procedures, you jump to / call those addresses one after the other, and Tada! you've got literally all that's required to build one procedure dynamically from two different ones.
> Go to store, eat chicken.
> What chicken?
That depends on your domain. In this particular case, it could be the first chicken on the stack. It won't be a particularly tasty chicken, since it'll be entirely uncooked and probably frozen, but that's certainly within the realm of possibility.
> you've basically gave an example where you can do anything
Well yeah, welcome to Turing-completeness :)
> You need rules on what can compose with what.
Indeed, and the rules in that example would be:
1. There are two things on the stack, and those things are addresses of procedures to JMP or CALL into.
That's really all there is to it. If the arguments aren't valid pointers to procedures, then you crash :)
(There are of course Forth derivatives/dialects/descendants that do type checking, in which case you could verify that the two topmost items on the stack are pointers to procedures, but that's not strictly necessary for composition; just for making sure your composition procedure doesn't try to compose things that aren't procedures)
> Who writes business logic in Forth nowadays?
I picked Forth (or more specifically: an imaginary derivative thereof) for the procedure-composition example because it's simple to a fault, and because it's able to compile procedures at runtime. You pop things from the stack, you push things onto the stack. You pop two pointers, you store them in the necessary code to CALL or JMP to those pointers, and you push a pointer to that generated code. Tada! Composed.
You could do the same thing in Lisp, or in C/C++ (when linked to, say, LLVM, or when using a compiler that allows dropping down to assembly), or assembly, or in quite literally any other Turing-complete language with the ability to emit arbitrary code and JMP to it (and even then).
Again: not all bricks are Legos. Nothing wrong with needing mortar and rebar to build something.
- crimsonalucard 7y ago>Tada! composeObjects cannot compose correctly. The nature of objects is to know the domain. Food is a composition of ingredients and cooking. However you can eat food and take it to go, because during composition, the context of what food is, is added. Your composition method cannot do this, it does not know about context. A tuple (cooking, ingredients) has no domain knowledge. Your composition is mashing random stuff together. It is not correct. It is the same as creating a tuple or list of two objects, with no concept of Food. >That depends on your domain. In this particular case, it could be the first chicken on the stack. It won't be a particularly tasty chicken, since it'll be entirely uncooked and probably frozen, but that's certainly within the realm of possibility. No it's not. Domain matters, otherwise programs are meaningless. Composition without domain proves nothing. >Well yeah, welcome to Turing-completeness :) Why are you welcoming me to something you don't understand. Everyone knows what turing completeness is, therefore everyone knows that you can imitate features of one primitive with features from another if the underlying system is turing complete. So what is the point of your whole expose? Let me answer for you: there is no point. When someone says that C++ supports types and python doesn't we have a guy here who says "well python does support types: look I wrote a whole C++ compiler with type checking in python...." You are that guy. Technically correct, but Literally going nowhere with all your points. >Indeed, and the rules in that example would be: >1. There are two things on the stack, and those things are addresses of procedures to JMP or CALL into. >That's really all there is to it. If the arguments aren't valid pointers to procedures, then you crash :) No dude. By rules I mean domain specific rules. Not arbitrary rules of the language. The composition of step1 and step6 is illegal because it doesn't make sense even though you can do it in forth. >You could do the same thing in Lisp, or in C/C++ (when linked to, say, LLVM, or when using a compiler that allows dropping down to assembly), or assembly, or in quite literally any other Turing-complete language with the ability to emit arbitrary code and JMP to it (and even then). Again you can do anything with any language therefore all languages are isomorphic and there's no differences among any languages. Dude. Come on. Objects and procedures do not compose, unless you bend them to imitate functions. You can do this in C++, lisp anything, including Forth. This is an obvious fact. Therefore nobody brings it up. Except you. >Again: not all bricks are Legos. Nothing wrong with needing mortar and rebar to build something. Buildings aren't programs built to be refactored and changed on a very dynamic basis. If you want your program to be scalable (which buildings aren't) modular (which buildings aren't) refactorable (which buildings aren't) then you need to build with legos. Mortar limits scalability which is a feature 90% of programs want but fail to have. If you want your program to be glued together like a giant monolith, be my guest, use the mortar.