Good case for a Lambda function?

I’m using: SWI-Prolog version 8.0.2.

Is the code below a good case for refactoring using a Lambda function for the findall() operation? If so, can someone show me how this would be done? The code seems a bit verbose too me (I wrote it so no one will be offended if you agree that it’s too vebose).

Also, I assume I would need to include the yall package and if so, will that package be allowed in the PEngines sandbox?

		% ----->>>>> adjective_filter_word.
		
		% These are the words that we don't want in the adjective words list 
		%	when building the an adjectival noun phrase.
		adjective_filter_word(unlocks) :- !.
		
		% ----->>>>> is_not_filter_word
		
		is_not_filter_word(AdjWordsList, Word) :-
			member(Word, AdjWordsList),
			\+ adjective_filter_word(Word).
		
		% Empty adjective words list.
		filter_adjective_words_list_1([], []) :- !.
		
		filter_adjective_words_list_1(AdjWordsList, FilteredWordsList) :-
			findall(Word, is_not_filter_word(AdjWordsList, Word), FilteredWordsList).

Difficult to judge what the code does. It even doesn’t have mode annotations. For example do you want, the second argument is output:

% is_not_filter_word(+List,-Word)

Or is it rather, the second argument is input:

% is_not_filter_word(+List,+Word)

In the later case I would use memberchk/2 to speed up things. Or avoid lists alltogether and go with facts, so that indexing can do its work.

How to annotate with modes is documented here, see Fig 4 ff:

Coding Guidelines for Prolog

2 Likes

Wow, quite the Hall of Fame list of authors on that paper! Pretty much a programming dream team for any company running a production version of Prolog. :slight_smile:

Thanks for the link! That one should go in the forum introductory E-mail, my opinion.

1 Like