[m-users.] Conjunction as an operator

Julian Fondren jfondren at minimaltype.com
Sun Oct 13 10:52:30 AEDT 2019


On 2019-10-12 18:29, Volker Wysk wrote:
> Am Samstag, den 12.10.2019, 17:42 -0500 schrieb Julian Fondren:
>> On 2019-10-12 17:32, Volker Wysk wrote:
>> > Hi!
>> >
>> > I need a conjunction of two terms, like this:
>> >
>> >     X = (Str \= "" & Str \= ".")
>> >
>> 
>> What is X supposed to be, here? What is its type? Whats a possible
>> value that it could have?
> 
> X should be a boolean value, "yes" or "no".

   X = ( if Str \= "", Str \= "." then yes else no )

will do that then. When your goals are predicates you can pass around
zero-arity curries of them:

   :- module tobool.
   :- interface.
   :- import_module io.
   :- pred main(io::di, io::uo) is det.
   :- implementation.
   :- import_module bool, list.

   main(!IO) :-
       io.command_line_arguments(Args, !IO),
       ( if Args = [Str] then
           X = unify(Str, "") `andn` unify(Str, "."),
           io.print_line(X, !IO)
       else
           true
       ).

   :- func (pred) `andn` (pred) = bool.
   :- mode ((pred) is semidet) `andn` ((pred) is semidet) = out.
   G1 `andn` G2 = B :-
       ( if G1 ; G2 then
           B = no
       else
           B = yes
       ).

but it's likely that you don't really need bool values.

As you didn't here.

  But I've messed up, it
> shouldn't be done this way. I wanted to use it as the predicate in a
> "filter" call, like:
> 
> slice_path_1(PfadL) =
>     filter( (func(Str::in) = Str \= [] && Str \= ['.']),
>             split(PfadL)
>           ).
> 
> Now I've figured it out:
> 
> slice_path_1(PfadL) =
>     filter( (pred(Str::in) is semidet :-
>                  Str \= [],
>                  Str \= ['.']),
>             split(PfadL)
>           ).
> 
> Old habits from Haskell.
> 
> 
>> If you want to fail if Str is either ""
>> or ".", you can do that with any of
>> 
>>    Str \= "", Str \= "."
>> 
>>    not (Str = "" ; Str = ".")
>> 
>>    ( if Str = "" ; Str = "." then fail else true )
>> 
>> A,B and A&B only differ operationally: A and B might be executed in
>> parallel in the second case.
>> 
>> > This doesn't work. I'm sure I don't understand what's going on.
>> > Could
>> > somebody please tell me how this is done?
>> >
>> > Volker


More information about the users mailing list