[erlang-questions] how to create user-defined guards

Ivan Carmenates Garcia icarmenates@REDACTED
Mon Apr 27 01:12:54 CEST 2009


Hi all,

I have a problem if for example I have an mnesia cosult like this 

get_students()->
        F = fun()->
                mnesia:select(person_table, [{#person_table{
                        id          ='$1',
                        name     ='$2',
                        group    ='$3',
                        type      ='$4',
                        id_card ='$5',
                        user      ='$6'},
                        [{'=:=', {is_student,'$4'}, true}],
                        ['$_']}])
        end,
        mnesia:transaction(F).

is_student(X)->
        if X == "Estudiante"->
                true;
        true->
                false
        end.

that's only accept guards, for exaple changing  [{'=:=', {is_student,'$4'}, true}], by  [{'=:=', {is_list,'$4'}, true}], then that work fine

because is_list is a guard, but I need to check for more complex criterias, but using my own funtion criteria I just got

{aborted,{badarg,[person_table,
                  [{{person_table,'$1','$2','$3','$4','$5','$6'},
                    [{'=:=',{is_student,'$4'},true}],
                    ['$5']}]]}}

because is_student is not valid guard.

How can I simulate or make my own guard or do something else to resolve this problem.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 5770 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090426/5ecd1644/attachment.bin>


More information about the erlang-questions mailing list