If you want to check whether a record contains a value as a key, you
can use "Record.hasFeature":
{Show {Record.hasFeature unit(test:42) test}}
This is an efficient function with constant lookup time.
If you want to know whether one of the fields of a record is equal to
a value, you can either convert it to a list and use List.member, like
this:
{Show {List.member 42 {Record.toList unit(test:42)}}}
Or you use the high-order function Record.some like this:
{Show {Record.some unit(test:42) fun {$ V} V==42 end}}
Both of these methods have a O(N) lookup time, i.e. the larger the
record, the slower the test will be.
Hope this helps,
Wolfgang
On Sun, Oct 3, 2010 at 2:15 PM, Peter Breitsprecher
<[email protected]> wrote:
> I am trying to write a very simple little program that will search a record
> and give me a result of true if the word is in the record, false if it
> isn't.
>
> as an example...
>
> Lex=lex(1:X1 2:X2 3:X3 4:X4)
>
> declare
> fun {IsItThere W}
> if Lex.W \=nil then true
> else
> false
> end
> end
>
> Firstly it doesn't work right, and I think I have the semantics wrong for
> using a record. If it were a list i would use the case statement and pull
> the head off compare them, and repeat it until the list was nil. But for a
> record to see if it is in there at all, you just have to {Browse Lex.W} and
> it would come up with the result if it is there or an error if it isn't.
> Can I make this a boolean function easily?
>
> Kurt
> --
> Kurt Breitsprecher
> (807) 474-9601
> [email protected]
>
> _________________________________________________________________________________
> mozart-users mailing list
> [email protected]
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users