freenode/#lisp - IRC Chatlog
Search
7:09:44
ArthurStrong
It's character name from the TV series. https://en.wikipedia.org/wiki/Count_Arthur_Strong_(TV_series)
10:41:31
froggey
can (locally (declare (type fixnum *unbound-special-variable*)) nil) signal an unbound variable error?
10:41:40
froggey
from the TYPE declaration page: "The meaning of a type declaration is equivalent to [...] executing (the typespec var) at the moment the scope of the declaration is entered."
11:04:06
froggey
(locally (the fixnum *unbound-special*) nil) does, which I'd expect to be equivalent
11:06:50
phoe
froggey: in that case file a SBCL issue, since it's likely an issue with SBCL's approach "treat type declarations as assertions"
11:14:15
froggey
it's not just SBCL, this is how other implementation behave too. (the <type> *unbound*) signals an error, but (declare (type <type> *unbound*)) doesn't
11:14:57
froggey
I'm wondering if it is reasonable for an implementation to have the declare signal an unbound variable error too
11:19:53
phoe
only if the variable is tried to be accessed an unbound variable error is to be signaled
11:21:27
froggey
it's equivalent to (defun foo () (the fixnum *foo*) (if (frob) (the fixnum *foo*) *bar*))
11:22:09
froggey
on variable reads, writes, *and* on entry to the scope that the declaration applies to
11:23:14
phoe
so it is normal that at the entry to the function toplevel SBCL complains about unbound variable
11:23:53
phoe
you want (defun foo () (if (frob) (locally (declare (fixnum *foo*)) *foo* *bar)) instead
11:26:13
froggey
SBCL *currently* does (defun foo () (if (frob) (the fixnum *foo*) *bar*)), not what I said
11:26:42
froggey
I'm wondering if my reading of the spec, which would allow an implementation to do (defun foo () (the fixnum *foo*) (if (frob) (the fixnum *foo*) *bar*)), is correct
11:28:10
phoe
I'm not able to pay too much energy towards checking this one - I'm fighting the spec on another field
11:44:57
jackdaniel
froggey: I think I've read somewhere that declarations are hints for the compiler and it doesn't have to take that into account (also, if the declarations is invalid then it is an undefined behavior)
11:46:04
jackdaniel
i.e when type is declared, compiler is entitled to assume that declaration is correct and i.e inline accesses for the particular data type without checking for the type. that said sbcl i.e expands such declaration into check-type if it doesn't know for sure what the type is
11:46:19
jackdaniel
ecl otoh on low safety settings will take that at face value and segfault on invalid declaration
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)