< Back to IRCAM Forum

Filtering a list, obtaining integer values only

Hi there,

I have a list containing integers and fractions and I need to remove the fractions from the list, obtaining only the integer values. Any clue how to do this?

Ex:

I have this: (1 2 3/4 5/8 7)
The result should give me this (1 2 7)

All the best,
George.

Hi George

I suggest you use the ratiop predicate (see attached), which sends T for ratios and NIL for everything else.

According the type of you want to identify (atoms, lists, strings, even or odd numbers, positive or negative, etc.)

you can very often find the corresponding predicate with the type name ending plus p (like predicate).

Best

Julien

facebook_like_button_big1.jpg

…or use of of remove-if / remove-if-not using 'ratiop or 'integerp as “predicate”

Follow-up question:

Will these solutions also work with ratios like 4/4 og 14/7?

Rune.

Thanks a lot Michelezaccagnini, Karim and Jean Bresson, that solved my problem!

:slight_smile: