all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* type checking for arbitrary lisp objects
@ 2014-04-11 19:10 Roland Winkler
  2014-04-11 19:12 ` Daniel Colascione
  0 siblings, 1 reply; 6+ messages in thread
From: Roland Winkler @ 2014-04-11 19:10 UTC (permalink / raw)
  To: emacs-devel

The function bbdb-check-type performs a type checking for atomic or
compound lisp objects by comparing these objects against patterns
that use a syntax kind of similar to the :type keyword used by
defcustom (but without the extra keywords such as :tag used by
defcustom).  So a typical pattern is something like the following

   (vector (or string (const nil))
           (repeat string)
           (repeat (vector string (repeat string)
                           string string))
           (repeat (cons symbol string))
           sexp)

I am just wondering: Am I here reinventing the wheel because
something similar has been developed already in some other package?
If not, could this possibly also be useful for other packages (for
example, for defining predicates used by the safe-local-variable
property)?

Roland



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: type checking for arbitrary lisp objects
  2014-04-11 19:10 type checking for arbitrary lisp objects Roland Winkler
@ 2014-04-11 19:12 ` Daniel Colascione
  2014-04-11 19:22   ` Roland Winkler
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Colascione @ 2014-04-11 19:12 UTC (permalink / raw)
  To: Roland Winkler, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 943 bytes --]

On 04/11/2014 12:10 PM, Roland Winkler wrote:
> The function bbdb-check-type performs a type checking for atomic or
> compound lisp objects by comparing these objects against patterns
> that use a syntax kind of similar to the :type keyword used by
> defcustom (but without the extra keywords such as :tag used by
> defcustom).  So a typical pattern is something like the following
> 
>    (vector (or string (const nil))
>            (repeat string)
>            (repeat (vector string (repeat string)
>                            string string))
>            (repeat (cons symbol string))
>            sexp)
> 
> I am just wondering: Am I here reinventing the wheel because
> something similar has been developed already in some other package?
> If not, could this possibly also be useful for other packages (for
> example, for defining predicates used by the safe-local-variable
> property)?

Why not use cl-deftype?


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 901 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: type checking for arbitrary lisp objects
  2014-04-11 19:12 ` Daniel Colascione
@ 2014-04-11 19:22   ` Roland Winkler
  2014-04-11 20:03     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Roland Winkler @ 2014-04-11 19:22 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: emacs-devel

On Fri Apr 11 2014 Daniel Colascione wrote:
> Why not use cl-deftype?

...Interesting! - I guess the main difference to what I have in mind
is that cl-deftype appears to require some lisp code for FORMS.
I am thinking about replacing these forms by some more readable
pattern such as the one I included in my first post.  The function
bbdb-check-type then compares an arbitrary lisp object against such
pattern.  I find it more readable and also more flexible to define
patterns instead of hacking actual code.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: type checking for arbitrary lisp objects
  2014-04-11 19:22   ` Roland Winkler
@ 2014-04-11 20:03     ` Stefan Monnier
  2014-04-12  3:32       ` Roland Winkler
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2014-04-11 20:03 UTC (permalink / raw)
  To: Roland Winkler; +Cc: Daniel Colascione, emacs-devel

>> Why not use cl-deftype?
> ...Interesting! - I guess the main difference to what I have in mind
> is that cl-deftype appears to require some lisp code for FORMS.
> I am thinking about replacing these forms by some more readable
> pattern such as the one I included in my first post.  The function
> bbdb-check-type then compares an arbitrary lisp object against such
> pattern.  I find it more readable and also more flexible to define
> patterns instead of hacking actual code.

AFAIK cl-deftype is specifically there to define those patterns, so you
can later pass them to cl-check-type.


        Stefan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: type checking for arbitrary lisp objects
  2014-04-11 20:03     ` Stefan Monnier
@ 2014-04-12  3:32       ` Roland Winkler
  2014-04-12 13:16         ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Roland Winkler @ 2014-04-12  3:32 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Daniel Colascione, emacs-devel

On Fri Apr 11 2014 Stefan Monnier wrote:
> AFAIK cl-deftype is specifically there to define those patterns, so you
> can later pass them to cl-check-type.

I begin to understand how this is supposed to work.  Is it also
possible to define more complex types recursively, similar to `list'
and `repeat' used by defcustom's :type keyword?  My complete
knowledge about these cl functions is based on their info page,
which is somewhat brief.

Thanks.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: type checking for arbitrary lisp objects
  2014-04-12  3:32       ` Roland Winkler
@ 2014-04-12 13:16         ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2014-04-12 13:16 UTC (permalink / raw)
  To: Roland Winkler; +Cc: Daniel Colascione, emacs-devel

> I begin to understand how this is supposed to work.  Is it also
> possible to define more complex types recursively, similar to `list'
> and `repeat' used by defcustom's :type keyword?  My complete
> knowledge about these cl functions is based on their info page,
> which is somewhat brief.

If you do a search for "clhs deftype" on your favorite search engine
you should find the Common Lisp doc for that macro.  The cl-lib version
may not be 100% faithful, but it's usually pretty close,


        Stefan



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-04-12 13:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-11 19:10 type checking for arbitrary lisp objects Roland Winkler
2014-04-11 19:12 ` Daniel Colascione
2014-04-11 19:22   ` Roland Winkler
2014-04-11 20:03     ` Stefan Monnier
2014-04-12  3:32       ` Roland Winkler
2014-04-12 13:16         ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.