[mercury-users] $pred doesn't work in lambda expressions
Ian MacLarty
maclarty at csse.unimelb.edu.au
Fri Jul 25 08:49:01 AEST 2008
On Thu, Jul 24, 2008 at 12:18 PM, Julien Fischer
<juliensf at csse.unimelb.edu.au> wrote:
>
> On Thu, 24 Jul 2008, Peter Ross wrote:
>
>> On Thu, Jul 24, 2008 at 10:55 AM, Peter Wang <novalazy at gmail.com> wrote:
>>>
>>> On 2008-06-26, Peter Wang <novalazy at gmail.com> wrote:
>>>>
>>>> On 2008-06-26, Nicholas Nethercote <njn at csse.unimelb.edu.au> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I tried using $pred in a lambda expression and got this:
>>>>>
>>>>> Uncaught Mercury exception:
>>>>> Software Error: hlds_code_util.m: Unexpected: cons_id_to_tag:
>>>>> implementation_defined_const
>>>>>
>>>>> It's easy to work around, but I thought it might be worth mentioning.
>>>>
>>>> Thanks for pointing it out. Added to the bug tracker.
>>>
>>> This was fixed about a month ago. However,
>>>
>>> main(!IO) :-
>>> P = (pred(!.IO::di, !:IO::uo) is det :-
>>> io.write_string($pred, !IO),
>>> io.nl(!IO)
>>> ),
>>> P(!IO).
>>>
>>> will print
>>>
>>> predicate `pre.main'/2
>>>
>>> which, while correct by one view, seems counter-intuitive.
>>> Any suggestions on how to expand $pred in lambdas?
>>>
>> I would suggest "lambda in pre.main/2 on line xx"
>
> What would happen for nested lambdas? Would it be
>
> lambda in lambda in pred.main/2 on linx xx
>
> What if I have two lambda expressions on a single line?
> (It's not something I am likely to do in practice but it is possible?)
>
> What do the debugger/profilers do when printing out the names of
> lambdas?
>
The debugger uses something like pre.lamda_pre_m_14 (so "lamba_"
followed by the filename (with '.' replaced by '_') followed by the
line number. The enclosing predicate is not mentioned.
Personally I think $pred is fine as it is. $pred gives you the
(named) enclosing predicate. If you want more context you have $line
and $file.
I don't like "lambda in pre.main/2 on line xx" because it complicates
the format of the $pred string. What if you have some code that
parses the $pred string to get the arity, for example?
Ian.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list