Re: Type BOOLEAN

Kevin Rosenberg <kevin-HJRc7zDS/[email protected]>
Newsgroups gmane.lisp.clsql.devel
Message-ID <[email protected]>
Edi Weitz wrote:
> then current CLSQL will raise an error because the result of FIND is
> most likely neither T nor NIL. I think it's more Lisp-y to allow for
> generalized booleans in this case. It's just that the docs should make
> clear that reloading these instances from the SQL database will give
> you T or NIL and nothing else.

Well, it depends upon how you define "Lisp-y". I've wrestled a bit
with the slot type representing an actual Lisp type versus representing a
SQL data type.

> Any objections?

To the degree, that "declaration are assertations", it's not okay to
lie to Lisp. This is implementation specific, of course. OpenMCL, for
example, computes a slot named ccl:type-predicate for each
effective-slot-definition. It uses this predicate to check values
stored with (setf slot-value-using-class).

As an example:

[email protected]:~> openmcl
Welcome to OpenMCL Version (Beta: Linux) 0.14.2!
? (defclass foo () ((a :initarg :a :type boolean)))

? (make-instance 'foo :a (find 'b '(a b c)))
> Error in process listener(1): The value B, derived from the initarg
  :A, can not be used to set the value of the slot A in #<FOO
  #x354C6DA6>, because it is not of type (OR NULL BOOLEAN). 
> While executing: CCL::%SHARED-INITIALIZE

I have arranged a hook in sql/metaclasses.lisp named
compute-lisp-type-from-slot-specification where it's possible to
change the actual lisp type for a :type attribute in a slot. So, it is
possible to have ":type boolean" actually translate to lisp as ":type
t". While possible, I've tried to stick as much to Lisp semantics as
possible such that:
  (typep slot-value slot-type) => t

As stated, I've thought about this issue and I'll be glad to discuss
it further. 

Kevin







> Cheers,
> Edi.
> 

> +++ oodml.lisp	2004-06-09 01:29:01.000000000 +0200
> @@ -142,7 +142,8 @@ (defun check-slot-type (slotdef val)
>    (let* ((slot-type (specified-type slotdef))
>           (basetype (if (listp slot-type) (car slot-type) slot-type)))
>      (when (and slot-type val)
> -      (unless (typep val basetype)
> +      (unless (or (eq basetype 'boolean)
> +                  (typep val basetype))
>          (error 'sql-user-error
>  	       :message
>  	       (format nil "Invalid value ~A in slot ~A, not of type ~A."

> _______________________________________________
> CLSQL-Devel mailing list
> [email protected]
> http://lists.b9.com/mailman/listinfo/clsql-devel

-- 
Kevin Rosenberg
kevin-HJRc7zDS/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.