- (define-procedure-tag constructor-name predicate-name accessor-name)syntax
define-procedure-tag is a define form. The subforms are all identifiers.
define-procedure-tag binds the identifiers constructor-name, predicate-name, and accessor-name to three procedures for a newly-created tagging protocol.
The constructor name is bound to a constructor procedure of two arguments, tag and proc. proc must be a procedure, referred to as the underlying procedure. When invoked, the constructor procedure returns a new procedure object which has identical arity and behaviour as the underlying procedure, but is tagged in the new tagging protocol with the object tag. If the underlying procedure is already a tagged procedure in some protocol or protocols, the new tag is added in the newly-returned procedure to the existing ones, with the given tag; if one of those protocols is the created tagging protocol, the tag value for this protocol is effectively replaced with the new tag value. If a non-procedure is passed to the constructor, a condition of kind exn and type is raised.
The procedure object returned from the constructor procedure has a fresh location tag and is distinct from all existing procedures in the sense of the eqv?, eq?, and equal? procedures.
The predicate-name is bound to a predicate procedure of one argument. When this procedure is invoked, it returns #t if its argument is a procedure object that was created by a call to the constructor procedure, or #f otherwise.
The accessor-name is bound to an accessor procedure of one argument. Its argument is a procedure object created by a call to the constructor procedure. If the argument is not a procedure, a condition of kind exn and type is raised. If the argument is not tagged in the protocol, then a condition of kidn exn and assertion is raised. The accessor procedure returns the value of the tag which was provided when the constructor procedure was called.
define-procedure-tag is generative: every evaluation causes the creation of a new procedure tagging protocol, and the constructor, predicate, and accessor procedures created do not operate on tagged procedures with the protocol from previous or future evaluations of the same define-procedure-tag form.
Procedure tagging protocols do not create a disjoint type: the procedure? predicate answers #t on tagged procedures.