slack1
2018-4-5 00:52:43

How do people quickly check that they have a non-empty list of X?


brendan
2018-4-5 00:55:41

(not (null? xs))


brendan
2018-4-5 00:55:48

Where xs is my list


brendan
2018-4-5 00:57:44

There’s also (andmap (const #t) xs), but that’s a little less clear


slack1
2018-4-5 01:01:44

I seee


slack1
2018-4-5 01:02:35

I was just wondering because all? seems to return true if list is empty


brendan
2018-4-5 01:03:30

Okay, that actually does make sense and I screwed up in the exact same way here


brendan
2018-4-5 01:03:46

I should’ve used ormap above


brendan
2018-4-5 01:04:52

The thing is, it’s true the every value of the empty list satisfies e.g. odd? or boolean?


slack1
2018-4-5 01:05:00

What explains the first part or vs and?


slack1
2018-4-5 01:05:05

like


slack1
2018-4-5 01:05:18

how did you know ormap returns false for empty list


slack1
2018-4-5 01:05:25

because intuitively, I woudl’ve thought it was flip flopped


brendan
2018-4-5 01:05:57

Because I want the property that (ormap p (cons x xs)) is (or (p x) (ormap p xs))


brendan
2018-4-5 01:06:03

Does it make sense that that should be true?


slack1
2018-4-5 01:07:23

kind of -_-a


brendan
2018-4-5 01:08:57

Well, what should ormap do? Can you implement it as a recursive function/loop?


slack1
2018-4-5 01:10:48

I would imagine (ormap fn lst) means to map boolean function to list, and then if there’s a single true, return true


brendan
2018-4-5 01:10:59

Right!


slack1
2018-4-5 01:11:20

AHH


slack1
2018-4-5 01:11:20

yes


brendan
2018-4-5 01:11:21

Are there any elements of the empty list for which fn would return true?


slack1
2018-4-5 01:11:22

it makes sense


brendan
2018-4-5 01:11:26

:)


slack1
2018-4-5 01:11:32

the symmetry to andmap makes sense


slack1
2018-4-5 01:13:38

thanks!


brendan
2018-4-5 01:14:04

No problem. Sorry for getting it wrong in my initial explanation haha


slack1
2018-4-5 01:25:37

ahh no wait


slack1
2018-4-5 01:25:42

ormap isn’t what I’m looking for


slack1
2018-4-5 01:25:53

like


slack1
2018-4-5 01:26:27

(ormap integers? (1 2 'meow')


slack1
2018-4-5 01:26:46

would return true


brendan
2018-4-5 01:27:21

So do you want andmap but false for the empty list?


slack1
2018-4-5 01:27:23

yeah


brendan
2018-4-5 01:27:30

Why do you want to reject the empty list?


slack1
2018-4-5 01:27:38

Because I feel for a series of numerical operations


slack1
2018-4-5 01:27:44

You would propogate an empty list down


slack1
2018-4-5 01:28:59

like you’re checking if you have a non-empty list of only integers


slack1
2018-4-5 01:29:17

and you do an operation assuming you only have non-empty lists


brendan
2018-4-5 01:30:30

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