freenode/#lisp - IRC Chatlog
Search
11:59:05
froggey
point 3 from the TYPE page: "At the moment the scope of the declaration is entered, the consequences are undefined if the value of the declared variable is not of the declared type."
12:01:07
jackdaniel
compiler could expand this declaration to (the fixnum *foo*), if it is bound to fixnum then behavior is no different compared to a situation when such declaration does not exist
12:02:02
froggey
that's what I was thinking, but I can't find an implementation that does this, so I was a bit concerned
12:02:43
jackdaniel
you can but you don't have to. if you write a documentation for mezzano compiler I'd clarify how it handles this undefined behavior given it is clear
12:10:14
pfdietz
I don't think having a special variable be unbound would violate a type declaration.
12:10:53
pfdietz
The value of an unbound variable isn't not of the declared type, since there is no such value.
12:12:00
pfdietz
"executing (the typespec var) at the moment the scope of the declaration is entered. " Hmm
12:12:38
pfdietz
That just requires that the variable be bound to an appropriate value at that point.
12:15:36
pjb
pfdietz: good question. There's no type for unbound. But if you declare a variable to be of type X, there's also no value of type X for unbound! Therefore an implementation would be misdirected to use the unbound "value" of the variable as an X. Or it could store a prototypal X, and add an unbound flag. Which again shows that declaring types in CL only slows down the code, and makes it bigger…
12:16:01
pfdietz
So a global (declaim (type fixnum *foo*)) just means that at that particular point, when loading the file, *foo* must be bound.
12:22:22
jackdaniel
declaim and proclaim may do different things (especially in environments where we load already compiled files)
17:31:49
aeth
I think the first line ever in this channel must have been a #| or there's some custom reader macro
17:54:16
sjl
my brain isn't working today. If I have a sequence S and I want to get a fresh vector containing its elements, is there a better way than (map 'vector 'identity s)?
17:54:46
sjl
(coerce (copy-seq s) 'vector) would work, but if s is a list it would needlessly cons an intermediate list
18:01:34
sjl
looks like it's noticably faster if I write out the boilerplate http://paste.stevelosh.com/ff7cc9569ee6490aff8e3861ae8bb99da49dc2db
18:04:13
sjl
Another way would be (replace (make-array (length seq)) seq) but that's not ideal if length is slow (e.g. for lists)
19:19:33
Shinmera
but as phoe pointed out copying a list to an array will incur a length check anyway because resizing many times would be much more costly than counting precisely once.
20:34:01
Shinmera
last I looked at it for whatever reason make-array/replace was faster than initial-contents
20:39:55
_death
but confirmed here.. for a 1m elements simple-vector it takes about 3.802 ms for initial-contents vs. 3.236 ms for replace
20:43:38
pjb
Why not (defun make-array (…) … (when initial-contents (replace array initial-contents))) which should be as fast? (modulo recursion into the dimensions).
20:53:58
aeth
It depends on what the initial-contents are, of course. If they're a literal list, I think you hit the fast path, at least on SBCL