Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:20:25+00:00 2026-05-30T19:20:25+00:00

I think this is a scope related problem. If I have a rule on

  • 0

I think this is a scope related problem. If I have a rule on my object like this:

:- public(new/2).
:- mode(new(+list, -object_identifier), one).
new(Args, Instance) :-
    self(Self),
    create_object(Instance, [instantiates(Self)], [], []),
    Instance::process_arguments(Args).

I find this works fine if I do this dance:

:- object(name, instantiates(name)).

I don’t fully understand why this is necessary but I suspect it is linked to my actual problem, which is that if I have your standard Prolog loop in my object, like so:

process_arguments([Arg|Args]) :- process_arg(Arg), process_arguments(Args).
process_arguments([]).

process_arg(Arg) :- ::asserta(something(Arg)).

I find this use of ::asserta puts the facts in the right namespace (on the newly-created instance). However, if I get witty and replace the body of process_arguments/1 with this lambda expression:

process_arguments(Args) :- meta::map([Arg]>>process_arg(Arg), Args).

then I wind up with my facts being added to the parent class and shared by all the instances. If I replace it with this:

process_arguments(Args) :-
    self(Self),
    meta::map([Arg]>>(Self::process_arg(Arg)), Args).

then it works, but I have to make process_arg/1 a public rule when I’d rather not. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:20:26+00:00Added an answer on May 30, 2026 at 7:20 pm

    Let me start first with your snippet of code above where the object name instantiates itself. In doing this, you make name its own class. Nothing wrong where. In languages that support meta-classes, such as Smalltalk and Logtalk, making a class its own meta-class is a classical way of avoiding an infinite regression. See, for example the Wikipedia entry on meta-classes (http://en.wikipedia.org/wiki/Metaclass). See also the “reflection” example in the Logtalk distribution. By making the object name instantiate itself, it plays both the role of an instance (as it instantiates an object) and the role of a class (as it’s instantiated by an object). If you defined name as a stand-alone object, i.e. an object with no relation to other objects, it would be compiled as a prototype.

    Now to your question. In Logtalk, meta-predicates (such as meta::map/2) are called in the context of the sender. If the process_arguments/1 predicate is defined in name, then the execution context (including the value of self) will be name. Thus, the clauses for something/1 will be asserted in name. Your workaround (by using the built-in method self/1) works as expected but it does forces you to declare process_arg/1 public predicate. This is a bug in the stable Logtalk version as it should also work by declaring the process_arg/1 predicate protected or private (as the sender is name and the predicate is declared in the sender). For example:

    :- object(name,
        instantiates(name)).
    
        :- public(new/2).
        :- mode(new(+list, -object_identifier), one).
        new(Args, Instance) :-
            self(Self),
            create_object(Instance, [instantiates(Self)], [set_logtalk_flag(dynamic_declarations, allow)], []),
            meta::map({Instance}/[Arg]>>(Instance::process_arg(Arg)), Args).
    
        :- private(process_arg/1).
        process_arg(Arg) :-
            ::asserta(something(Arg)).
    
    :- end_object.
    

    I will push the bug fix into the publicly available Logtalk development version later this week. Thanks for driving my attention to this bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this must be simple but I can't get it right... I have
I think this mostly applies to web applications, since you often see things like
I think this is pretty typical, you have the same website project with an
This question is related to my other one and I hope to get some
The scenario is like this. I have a rich:tabPanel with about 5 tabs. On
This is a bit of a peculiar one; I don't think this is in
I've been reading about overloading new and delete (and related topics like placement new/delete).
I have a class with two definitions of ordering. (In the real problem, one
I think this is specific to IE 6.0 but... In JavaScript I add a
I think this is a multi-part question, so bear with me. Currently all of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.