freenode/#lisp - IRC Chatlog
Search
6:56:28
no-defun-allowed
map works best if you just have one function to "map" over, or you don't mind a small lambda
6:56:29
verisimilitude
So, if you know what you're doing ahead of time, LOOP is in all likelihood going to be more efficient.
6:56:58
verisimilitude
LOOP is also more general, being able to traverse hash tables and non-structures.
6:57:21
no-defun-allowed
loop executes entire expressions, which may be more wordy for simple things, but loop is probably less consy and faster than, say map + remove-if-(not) and related functions
6:57:59
no-defun-allowed
i wrote a test program which would try to buy low and sell high on one share over 100 days
7:00:34
hectorhonn
that means other than convenience, there is no particular reason to choose one over than the other right?
7:00:35
no-defun-allowed
it's not great though, usually about 10%ish profit over 100 days but you don't need an awful lot to win apparently
7:01:21
verisimilitude
So, if you know what you're doing ahead of time, use LOOP; in all likelihood, you will use LOOP more than MAP.
7:01:31
no-defun-allowed
>loop is probably less consy and faster than map with remove-if and other higher order functions, and works on expressions instead of functions
7:01:59
verisimilitude
Furthermore, LOOP permits doing more than traversing lists and whatnot, such as maintaining multiple numbers and other things.
7:02:32
no-defun-allowed
also true, map would require the likes of reduce or remove-if(-not) to further process results
7:03:24
no-defun-allowed
oh dear, that stuff about buying was directed for #lispcafe, please ignore that
7:04:16
sindan
if it's down to preference I go to great lengths to use map*, I think they are prettier. That said, loop does more, more elegantly, when more is needed.
7:05:05
no-defun-allowed
yeah, use map for the small things where you just need to call a function with each element, or you don't mind a small lambda to do it
7:41:12
hectorhonn
i think loop is nicer when there is some "state" to keep when progressing from one element to another. using map in that case would need an extra let clause.. just my 2c
7:50:24
sindan
yes, one nice side effect of loop (for me anyway) is that one avoids having to name variables that will do boring stuff. The code looks neater.
7:57:13
aeth
You use loop for things like conditional collect where you can't really use map like ":when foo :collect foo :into foos" because the alternative to that is remove after map
8:01:22
aeth
Similar reasons to use loop include conditional append (like above) and multiple return values (e.g. to build several lists at once)
11:46:30
jmercouris
however is there not a way to do what I want? or will I have to split apart my queries by semicolon or something...
11:50:06
jmercouris
so the only thing I can think of doing is splitting the string by semicolon and executing one query at a time..
11:50:33
jmercouris
however that seems very dumb and I feel like it should be possible to execute multiple queries...
12:08:28
jmercouris
I know that I'm doing two passes over the list and I could have done it more intelligently, I'm just thinking about stylistic changes