dilemma of load files as different objects

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: dilemma of load files as different objects

Post by Paulo Moura » Wed Aug 21, 2013 2:54 pm

shengcer wrote: OK, so I have decided to use "goal_extension" to work around this issue. I am wondering it is possible to

1. supply multiple hook objects to logtalk_load? I tried this,

Code: Select all

logtalk_load([
.....
], [hook(hook_obj1), hook(hook_obj2)]) .
but it does not work.
You can only specify an hook object for compiling a source file but an hook object can easily define expansion workflows that combine several hook objects, as illustrated by the "expansion" example.
shengcer wrote: 2. extend a parametric object? Documentation does not mention it.
Parametric objects can be extended as any other object but see above for the solution to use several hook objects for processing the same source file.
Paulo Moura
Logtalk developer

shengcer
Posts: 21
Joined: Wed Aug 14, 2013 7:54 pm

Re: dilemma of load files as different objects

Post by shengcer » Wed Aug 21, 2013 4:26 pm

expansion is pretty helpful :-)

so from my understanding

logtalk object = scala object
logtalk category = scala trait
logtalk protocol = scala interface

BTW - the way scala mixes multiple traits might be a better way for multiple extensions in logtalk.

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: dilemma of load files as different objects

Post by Paulo Moura » Wed Aug 21, 2013 5:09 pm

shengcer wrote: expansion is pretty helpful :-)

so from my understanding

logtalk object = scala object
logtalk category = scala trait
logtalk protocol = scala interface
In rough terms, yes. In Logtalk, object is a first class entity. Logtalk objects can play the role of classes, prototypes, superclasses, metaclasses, ... The role an object they plays is a function of its relation(s) with other entities. Logtalk predates Scala by five years and I will be interested if you find any functionality in Scala (or other OOP languages) that you think it would make a nice addition to Logtalk (without crossing the boundaries of a logic OOP language, that is).
shengcer wrote: BTW - the way scala mixes multiple traits might be a better way for multiple extensions in logtalk.
Not sure what you mean. Can you clarify? Point to an example? An object can already import one of more categories and using the alias/3 directive you can deal with any conflict arising from the mix.
Paulo Moura
Logtalk developer

shengcer
Posts: 21
Joined: Wed Aug 14, 2013 7:54 pm

Re: dilemma of load files as different objects

Post by shengcer » Wed Aug 21, 2013 9:35 pm

Oh, for mixin traits, I was just suggesting a possible way to resolve conflicts should a object need to extend multiple ones - Parents in the further right always wins.

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: dilemma of load files as different objects

Post by Paulo Moura » Wed Aug 21, 2013 9:50 pm

shengcer wrote: Oh, for mixin traits, I was just suggesting a possible way to resolve conflicts should a object need to extend multiple ones - Parents in the further right always wins.
In Logtalk, inherited predicate conflicts are automatically solved by default. The declaration or definition first found using a depth-first search wins. See the User Manual section on inheritance. When this doesn't give the desired outcome, the alias/3 allows you to define exactly want you want to inherit. Check the "aliases" example. The documentation and examples on categories will likely show you that you have nothing to miss from Scala in that department ;-) Also an interesting example on categories is the "patching" example (think Objective-C category functionality).
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests