序言问题:
请考虑以下格式:
carsCompany(Tel_Number,
Manager,
Company_Name,
[new_cars(Car_Name,info(Color,Creator),Date_Creation)],
[old_cars(Car_Name,info(Color,Creator),Date_Creation)]
]).
我想获取该实现已知的数据的所有信息。
示例:
carsCompany(1234,
Jujiro Matsuda,
Mazda,
[new_cars(mazda_3,info(Grey,Person1),26082016)],
[old_cars(Cosmo,info(Black,Person2),26081927),
[old_cars(RX-7,info(Black,Person2),26081979),]
]).
请给我
New = new_cars(mazda_3,info(Grey,Person1),26082016)
Old = old_cars(Cosmo,info(Black,Person2),26081927)
New = new_cars(mazda_3,info(Grey,Person1),26082016)
Old = old_cars(RX-7,info(Black,Person2),26081979)
我希望将所有可能的成员都加入New
和Old
中,以便我可以遍历它们。我知道我需要使用member
Prediec。
我该怎么办?
答案 0 :(得分:0)
您可以执行以下操作:
car_company( 1, phone, person('Jujiro', 'Matsuda'), 'Mazda' ).
production( 1, cars, new, 'Mazda-3', info( gray, person1 ), 26/08/2016 ).
production( 1, cars, old, 'Cosmo', info( black, person2 ), 26/08/1927 ).
production( 1, cars, old, 'RX-7', info( black, person2 ), 26/08/1979 ).
% query:
q :-
findall(
new_car( ID, Model ),
(
car_company( ID, Phone, person('Jujiro', 'Matsuda'), 'Mazda' ),
production( ID, cars, new, Model, info( Color, _ ), _ )
),
Result1
),
writeq( Result1 )
),
findall(
old_car( ID, Model ),
(
car_company( ID, Phone, person('Jujiro', 'Matsuda'), 'Mazda' ),
production( ID, cars, old, Model, info( Color, _ ), _ )
),
Result2
),
writeq( Result2 ).