How do people quickly check that they have a non-empty list of X?
(not (null? xs))
Where xs
is my list
There’s also (andmap (const #t) xs)
, but that’s a little less clear
I seee
I was just wondering because all?
seems to return true if list is empty
Okay, that actually does make sense and I screwed up in the exact same way here
I should’ve used ormap
above
The thing is, it’s true the every value of the empty list satisfies e.g. odd?
or boolean?
What explains the first part or
vs and
?
like
how did you know ormap
returns false for empty list
because intuitively, I woudl’ve thought it was flip flopped
Because I want the property that (ormap p (cons x xs))
is (or (p x) (ormap p xs))
Does it make sense that that should be true?
kind of -_-a
Well, what should ormap
do? Can you implement it as a recursive function/loop?
I would imagine (ormap fn lst)
means to map boolean function to list, and then if there’s a single true, return true
Right!
AHH
yes
Are there any elements of the empty list for which fn
would return true?
it makes sense
:)
the symmetry to andmap makes sense
thanks!
No problem. Sorry for getting it wrong in my initial explanation haha
ahh no wait
ormap
isn’t what I’m looking for
like
(ormap integers? (1 2 'meow')
would return true
So do you want andmap
but false for the empty list?
yeah
Why do you want to reject the empty list?
Because I feel for a series of numerical operations
You would propogate an empty list down
like you’re checking if you have a non-empty list of only integers
and you do an operation assuming you only have non-empty lists
So what operation are you doing which doesn’t make sense for an empty list? If you’re sure that you don’t want it you can just check that it’s nonempty before doing your series of numerical operations