Prolog:使用用户输入创建一个包含findall的列表

时间:2015-10-09 14:58:13

标签: list prolog user-input prolog-findall

所以我的问题如下:

我必须使用findall / bagof / setof命令创建一个列表。

这是我的数据文件:

musico('R. Stevie Moore').
musico('Lane Steinberg').
musico('Yukio Yung').
musico('Jessie Evans').
musico('Bettina Koster').
musico('Lucia Pamela').
musico('Shooby Taylor').
musico('Tiny Tim').
musico('Bettina Koster').
musico('The Legendary Stardust Cowboy').
album('R. Stevie Moore', 'Manuscription').
album('Lane Steinberg', 'Manuscription').
album('R. Stevie Moore', 'The Yung & Moore Show').
album('Yukio Yung', 'The Yung & Moore Show').
album('Jessie Evans', 'Autonervous').
album('Bettina Koster', 'Autonervous').
album('Lucia Pamela', 'Walking on the moon').
album('Shooby Taylor', 'The Human Horn').
album('Tiny Tim', 'God Bless Tiny Tim').
album('The Legendary Stardust Cowboy', 'Rock-It to Stardom').
formato('Rock-It to Stardom',vinil).
formato('Walking on the Moon',vinil).
formato('God Bless Tiny Tim',cd).
formato('Walking on the Moon',cd).
formato('Autonervous',cd).
formato('Manuscription',cd).
formato('The Human Horn',cassete).
formato('The Yung & Moore Show',cassete).
formato('Walking on the Moon',mp3).

我必须创建一个列表,其中包含与每张专辑相关联的所有音乐家(音乐人)。

我的意思是:

all_musicians_album([Z]) :-
    write('Write the name of the album : '),
    read(Y),
    findall(X, album(X,Y), Z).

这个想法是使用专辑(X,Y)上的用户输入专辑,这样它才能找到并添加到与该专辑相关联的音乐家名单。

这带来了两个我似乎无法解决的问题:

  1. 它不起作用,该功能将所有音乐家添加到列表中。
  2. 每次调用该函数时,它只适用于一个相册。是否可以在单个函数中执行此操作?就像将专辑和音乐人保存在列表中而不是将这些列表添加到单个列表中一样?或者我应该使用bagof而不是findall?
  3. 感谢您的帮助。

0 个答案:

没有答案
相关问题