libera/#commonlisp - IRC Chatlog
Search
8:05:42
beach
coat: Common Lisp is wonderful in that, instead of containing a function for every possible special case, it contains all the building blocks to make such functions yourself.
8:06:52
aeth
coat: For built-ins? Shouldn't matter. For user-defined functions? There can be a distinction if it gets redefined. (CLs can prevent things in the COMMON-LISP package from being redefined)
8:07:04
beach
coat: #'digit-char-p is preferable. You then clearly tell the person reading your code that it is the function you are passing, rather than the symbol.
8:07:22
moon-child
and I do wish cl had better tools (built-in) for tacit programming. It is cumbersome to write the above lambda, rather than (e.g.) (partial #'every #'digit-char-p)
8:07:56
beach
moon-child: Oh? From the videos of C++ "standardization" that I have watched. The process is mainly about introducing more special cases every iteration.
8:08:45
aeth
moon-child: beach is right, some languages love special cases, e.g. sum() is very common
8:09:34
aeth
at least, when we're talking about how to do simple tasks on sequences, which is the topic
8:10:13
pjb
coat: (ignore-errors (parse-integer "123" :junk-allowed nil)) #| --> 123 ; 3 |# (ignore-errors (parse-integer "1x3" :junk-allowed nil)) #| --> nil ; #<ccl::parse-integer-not-integer-string #x3020036F316D> |#
8:12:03
aeth
moon-child: but it winds up with what's idiomatic in the language... and in particular, what's optimal (since if a sum() or .sum() is built in, that's probably faster than their equivalent of (reduce #'+ ...) while if it's not built in, then the implementation will try to optimize (reduce #'+ ...) more)
8:12:56
coat
What is the difference between char and schar? http://www.lispworks.com/documentation/lw50/CLHS/Body/f_char_.htm is not easy to understand for me.
8:14:13
aeth
it's saying (through several hyperlinks) that schar only works on simple strings, which are simple-strings, i.e. http://www.lispworks.com/documentation/lw50/CLHS/Body/t_smp_st.htm#simple-string
8:14:57
aeth
simple arrays give certain guarantees. http://www.lispworks.com/documentation/lw50/CLHS/Body/t_smp_ar.htm#simple-array
8:15:02
moon-child
aeth: the particular case of 'sum' is a bad one, as it's likely to have different semantics: reducing floating-point error. More generally, compilers recognizing specific idiomatic forms (such as (reduce #'+)) doesn't scale outside of apl. More interesting things like loop unrolling and autovectorization any compiler worth its salt will do anyway, given the opportunity
8:17:07
beach
coat: The standard is very clear with its definition of SIMPLE for arrays, but it leaves a lot of decisions to the implementation when it comes to non-SIMPLE.
8:18:13
Colleen
Clhs: type simple-array http://www.lispworks.com/documentation/HyperSpec/Body/t_smp_ar.htm
8:19:39
pjb
beach: I don't see how the standard can forbid: (make-array 8 :element-type 'character :adjustable t :fill-pointer 0)
8:20:46
beach
The standard says: "The type of an array that is not displaced to another array, has no fill pointer, and is not expressly adjustable is a subtype of type simple-array."
8:21:55
pjb
Oh, ok. But then it doesn't say that simple-array have to be simple, ie. have to not be displaced, have no fill pointer or cannot be expressly adjustable.
8:23:38
coat
can this code be made simpler? https://plaster.tymoon.eu/view/2514 - I have repeated (char s n) calls. is there a way to put all the indices in the list, iterate over those indicies and collect (char s i) instead?
8:25:22
pjb
(coerce "1000-2000-30" 'list) #| --> (#\1 #\0 #\0 #\0 #\- #\2 #\0 #\0 #\0 #\- #\3 #\0) |#
8:26:57
coat
pjb: thanks! that would be useful if I wanted all characters. but I want to choose which indices I want so the LOOP solution is more useful for my specific problem.
8:29:05
pjb
(let ((string "1000-2000-30")) (coerce (remove #\- string) 'list)) #| --> (#\1 #\0 #\0 #\0 #\2 #\0 #\0 #\0 #\3 #\0) |#