Beginner: how to generate a list by recursion

I’m using: SWI-Prolog (threaded, 64 bits, version 8.3.9)

I want the code to: build a list of boolean

But what I’m getting is: false

My code looks like this:

floor_locations([ 0.0, 0.17, 0.33, 0.5, 0.67, 0.83, 1.0 ]).

cabin_location_is_reached( cabin_location, floor_location, true ) :-
	abs( cabin_location - floor_location ) =< 0.01.
cabin_location_is_reached( cabin_location, floor_location, false ) :-
	abs( cabin_location - floor_location ) > 0.01.

list_floors_to_be_served( [], [],_, [] ).
list_floors_to_be_served( [request|floor_requests], [floor_location|floor_locations], cabin_location, [has_to_be_served|floors_to_be_served_list] ) :-
	cabin_location_is_reached( cabin_location, floor_location, has_to_be_served ),
	list_floors_to_be_served( floor_requests, floor_locations, cabin_location, floors_to_be_served_list ).

The expected result: [false, false, false, false, false, false, true]

This is double posted at StackOverflow: Generate list in place of ‘false’


Variables in Prolog start with a capitol letter, so cabin_location should be Cabin_location.

As this looks like a homework assignment I won’t solve this or give you more info so that you can learn from this bit of help. :slightly_smiling_face:

1 Like

Thanks!
No, it’s not a homework assignment.
I’m 54 years old, C:C++, Java programmer :slight_smile:

Then should the answer be

[true, false, false, false, false, false, false]

since for

floor_locations([ 0.0, 0.17, 0.33, 0.5, 0.67, 0.83, 1.0 ]).

only 0.0 is less than or equal to 0.01