Skip to content

Rewrite cons-specifier-ctype as generic function#8

Merged
Bike merged 1 commit intos-expressionists:mainfrom
digikar99:generic-cons-specifier-ctype
Jun 10, 2021
Merged

Rewrite cons-specifier-ctype as generic function#8
Bike merged 1 commit intos-expressionists:mainfrom
digikar99:generic-cons-specifier-ctype

Conversation

@digikar99
Copy link
Copy Markdown
Contributor

This is intended to fix #6

IIUC the issue about multiple return values for ctypep would be a different one. This extensibility at least allows for type specifiers with definite semantics - so ctypep returning a single return value works correctly for such specifiers, eg:

(defclass cstring= (ctype)
  ((string :initarg :string :reader cstring=-string :type string)))

(defun cstring= (string)
  (make-instance 'cstring= :string string))

(defmethod cons-specifier-ctype ((head (eql 'string=)) rest env)
  (declare (ignorable env))
  (destructuring-bind (string) rest
    (cstring= string)))

(defmethod unparse ((ct cstring=))
  `(string= ,(cstring=-string ct)))

(defmethod ctypep (object (ct cstring=))
  (and (stringp object)
       (string= object (cstring=-string ct))))

;;; so, (ctypep "qwerty" (specifier-ctype '(string= "qwerty"))) ;=> T

;;; and some more methods

@Bike Bike merged commit 5ecfb21 into s-expressionists:main Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extensible cons-specifier-ctype

2 participants