freenode/#lisp - IRC Chatlog
Search
22:53:52
aeth
pjb: Type rules would be the hard part to solve, but imo would be worth solving. It would mostly be AND/OR combinations as well as numbers and sequences that would be tricky. Hard, but a finite problem.
22:55:43
aeth
Satisfies would be impossible to solve here afaik. Would probably just be best to extend deftype at that point.
23:07:12
aeth
pjb: well, having a method that could override the default for a class would be preferable to a specified initial-element every time imo
23:08:45
aeth
Types are trickier. "Closest to 0 in a range and of the simplest type" probably makes the most sense for numbers. "Closest to length 0 and if not length 0 filled with elements of the default" makes the most sense for a sequence type. AND, OR, SATISFIES, etc., might be too hard, although I'd really like to see (or null foo) work at the very least.
23:18:52
pillton
I'm not sure all of this complexity is worth it. What is appropriate depends on the context as is illustrated by finding the maximum element of an empty sequence.
23:23:31
aeth
pillton: But it would be very useful for custom defstructs/defclasses where you provide a type and get a reasonable default value from that automatically, even if no implementation uses it for LOOP, MAKE-ARRAY, and wherever else the standard uses defaults.
23:25:10
aeth
Right now the only easy automatic default value is NIL, which requires the type to be (or null ...) or one of the handful of types that supports NIL (list, sequence, symbol, boolean, T, etc.)
23:26:26
aeth
You also see default values in gethash and a few other places (in the function calls themselves), which other macros/functions might want to override in a somewhat smart way.
23:43:39
pillton
For that case you could use the prototype object specified by MOP. (What I and pjb said before).
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)