I want to create in my object "main" instances of type "student". I have read the Logtalk documentation and looked through the examples that come with Logtalk, but I still do not understand
Logtalk provides a built-in predicate, create_object/4, that allows creation of new objects at runtime. This predicate is usually used as a primitive for more sophisticated behavior (e.g. for implementing creation of class instances; check the "roots" example). Note that Logtalk supports both prototype-based and class-based object designs. The built-in predicate create_object/4 may be used for both. Objects, including class instances may also be defined in a source file that you compile and load. If you provide a description of what you're trying to accomplish I should be able to provide you with more specific guidance. Nevertheless, try the following small example:
Code: Select all
write('New student instance: '), writeq(Student), nl.
Save the above code in e.g. a "student.lgt" source file, start Logtalk and try the following query:
Keep in mind that there is nothing special on the predicate new/1 being used above. Or, for that matter, on the code on the "roots" example. You can design your own instance creation methods to fit your application requirements.
Hope this helps. Best regards,