[mercury-users] Human beats compiler?
Michael Day
mikeday at yeslogic.com
Mon Jan 5 16:00:58 AEDT 2009
Hi Julien,
> I'd be interested in how far the current mode analyser allows you take
> this approach. For list(int) it's probably okay, for lists of
> non-atomic types it might get "interesting".
In some circumstances it works, when the items in the list don't need to
be touched too directly, otherwise it's back to using copy or at worst
unsafe_promise_unique.
> Well, it certainly won't work in the java, il and erlang grades ;-)
Did I mention that I think Mercury has too many grades? :)
> It works in both the asm_fast and hlc grades because they both use
> the same data representation. It won't work in grades that use
> --high-level-data, e.g. hl.gc. (Although, if you use MR_list_cons
> and friends from the runtime instead of MR_hl_field and MR_mktag
> directly, you could probably write a version that does.)
Good idea, that makes the code more readable anyway. How about this:
:- pragma foreign_proc(c,
filter_neg(Xs::di, Ys::uo),
[will_not_call_mercury, thread_safe, promise_pure], "
Ys = Xs;
while (!MR_list_is_empty(Xs))
{
MR_Integer X = (MR_Integer) MR_list_head(Xs);
MR_Word Xs0 = MR_list_tail(Xs);
if (X < 0)
{
MR_list_head(Xs) = 0;
}
Xs = Xs0;
}
").
However, the real challenge is to start doing more useful things with
lists, which will probably involve calling back to Mercury predicates
similar to map.
Cheers,
Michael
--
Print XML with Prince!
http://www.princexml.com
--------------------------------------------------------------------------
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