Re: Bit flags...

emacstheviking <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <CAEiEuUK2Z-mY5NfhQ5x-39_U2ZU_+7Qp=AOZqHFLzmEBQUccWw@mail.gmail.com>
My final solution is this, which works and doesn't use global state:

accflag(0x0001, public).
accflag(0x0010, final).
accflag(0x0020, super).
accflag(0x0200, interface).
accflag(0x0400, abstract).

access_flags(Value, Output) :-
    findall(X, flag_check(Value, X), Output).

flag_check(Value, Output) :-
    accflag(B, Output),
    On is Value /\ B,
    On > 0.

Many thanks to Michał Bieliński for invaluable assistance, well, the answer
pretty much, I just have to grok it now!

Excellent! :)

Sean.

On 23 October 2014 00:25, "Michał Bieliński" <[email protected]> wrote:

> Dnia 22 Października 2014, 00:54, Śr, emacstheviking napisał:
> > I really didn't think this would be so difficult! I have tried for
> > several hours now to find an elegant solution to my problem:
> > given a 32 bit value, create a list of atoms that represent
> > the names of those bit positions of interest.
>
> Until this point it sounds easy.
>
> > %% these define the bit positions of interest
> > accflag(0x0001, public).
> > accflag(0x0010, final).
> > accflag(0x0020, super).
> > accflag(0x0200, interface).
> > accflag(0x0400, abstract).
>
> Bit positions those are not. They are bit values.
>
> Those are bit positions:
> accflag(0, public).
> accflag(4, final).
> accflag(5, super).
> accflag(9, interface).
> accflag(10, abstract).
>
> > %% predicate to convert Value into a list of accflag/2 names.
>
> My way:
>
> access_flags(Value, Output) :-
>     findall(X, flag_check(Value, X), Output).
>
> flag_check(Value, Output) :-
>     accflag(X, Output),
>     g_assign(z, Value),
>     g_test_set_bit(z, X).
>
> > AAARGGGGH! Next month will be my 30th year in software and it
> > gets better every day!
>
> Just out of curiosity, how do you count the time? From your first hello
> world? From first year of working as programmer? Something else?
>
> --
> Michał Bieliński
>
>
> _______________________________________________
> Users-prolog mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/users-prolog
>

_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.