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
12:42:55
jmercouris
well at any rate, I will heed your advice since you are a more experienced developer than I
12:43:48
shka__
in that case, it may be a good idea to introduce new dynamic variable for stream to print such messages
12:44:49
jmercouris
if a user has access to these files, then the server is already fully compromised...
12:45:00
jdz
It's not very nice when somebody thinks they're just putting some SQL in some files, and suddenly program crashes.
12:46:10
jmercouris
however I still don't see how I can use cl-dbi to execute the contents of a SQL file
12:47:04
jmercouris
jdz: see this previously posted error: https://gist.github.com/jmercouris/2fb0215b5c9cc06db0400923b4a190b0
12:48:08
jmercouris
I'm not sure if this is a problem specific to the Sqlite driver and I won't have problems on postgres or mysql, however cl-dbi doesn't seem to have a "execute-queries" or something like that
12:48:09
jdz
Yes, that's an SQLite error. So you can use a real database, or have each SQL statement in a separate file.
12:51:27
jmercouris
anyways, it seems to be either a limition of the sqlite driver implemented for cl-dbi