Discussion:
using member in a compound type specification
(too old to reply)
David Richards
2020-04-06 16:03:50 UTC
Permalink
Hello All -
Trying to wrap my head around type specifiers and cannot figure out how to use 'member' in a compound type spec. If someone would kindly post a specific example I would be very appreciative...
Thanks!
Dave
t***@google.com
2020-04-06 22:44:08 UTC
Permalink
Post by David Richards
Hello All -
Trying to wrap my head around type specifiers and cannot figure out how to use
'member' in a compound type spec. If someone would kindly post a specific
example I would be very appreciative...
From the HyperSpec the MEMBER type specifier consists of a set of objects
which constitute the type. This is an explicit list of all of the actual objects that
make up the type. Symbols are unquoted in the set making up the members.

Some simple examples:
(typep 2 '(member 1 2 3)) ==> T
(typep 5 '(member 1 2 3)) ==> NIL
(typep 'b '(member a b c)) ==> T
(typep 'z '(member a b c)) ==> NIL

More complicated example:
(defstruct foo id)
(defvar *a* (make-foo :id "a"))
(defvar *b* (make-foo :id "b"))


;; Note the backquote on the first 2
(typep *a* `(member ,*a*)) ==> T
(typep *b* `(member ,*a*)) ==> NIL
(typep *a* '(member *a*)) ==> NIL (Because the struct is not the symbol '*a*)

So what are you trying to use MEMBER to express?
David Richards
2020-04-07 02:27:35 UTC
Permalink
Post by t***@google.com
Post by David Richards
Hello All -
Trying to wrap my head around type specifiers and cannot figure out how to use
'member' in a compound type spec. If someone would kindly post a specific
example I would be very appreciative...
From the HyperSpec the MEMBER type specifier consists of a set of objects
which constitute the type. This is an explicit list of all of the actual objects that
make up the type. Symbols are unquoted in the set making up the members.
(typep 2 '(member 1 2 3)) ==> T
(typep 5 '(member 1 2 3)) ==> NIL
(typep 'b '(member a b c)) ==> T
(typep 'z '(member a b c)) ==> NIL
(defstruct foo id)
(defvar *a* (make-foo :id "a"))
(defvar *b* (make-foo :id "b"))
;; Note the backquote on the first 2
(typep *a* `(member ,*a*)) ==> T
(typep *b* `(member ,*a*)) ==> NIL
(typep *a* '(member *a*)) ==> NIL (Because the struct is not the symbol '*a*)
So what are you trying to use MEMBER to express?
This great info - thank you very much! I'm simply trying to understand the LISP type system and was stumped with member. Clearly I misunderstood it. I was trying to build a compound type specifier for use inside of type-check.
t***@google.com
2020-04-07 17:39:16 UTC
Permalink
Post by David Richards
I was trying to build a compound type specifier for use inside of type-check.
For compound type specifiers you may need to use AND, OR and maybe NOT.
David Richards
2020-04-07 18:27:46 UTC
Permalink
Post by t***@google.com
Post by David Richards
I was trying to build a compound type specifier for use inside of type-check.
For compound type specifiers you may need to use AND, OR and maybe NOT.
Got it - I've had success with a variety of type spec examples I've been playing with. The examples were a great help! Thank you again!
Loading...