Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions csug/syntax.stex
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ With two arguments, \var{id} and \var{key}, \var{lookup} returns the
value of \var{id}'s \var{key} property, or \scheme{#f} if \var{id}
has no \var{key} property.

However, in the case of properties, there is a second, usually easier
way, to obtain property values, namely by calling the
\scheme{property-value} procedure described below.
Comment on lines +577 to +579
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For compile-time properties, the \scheme{property-value} procedure can be used instead of the lookup procedure in macro transformers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best wording probably depends on what the "recommended" way to retrieve property values should be. With property-value being available, I see no reason to use the older way for new code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to avoid making a recommendation and simply present the options.


%----------------------------------------------------------------------------
\entryheader
Expand Down Expand Up @@ -709,6 +712,29 @@ Attaching a new property with the same name as an property already
attached to a binding shadows the existing property with the new
property.

%----------------------------------------------------------------------------
\entryheader
\formdef{property-value}{\categoryprocedure}{(property-value \var{identifier} \var{key-identifier})}
\formdef{property-value}{\categoryprocedure}{(property-value \var{identifier} \var{key-identifier} \var{default})}
\returns see below
\listlibraries
\endentryheader

The \scheme{property-value} procedure returns the value of the
\var{key-identifier} property of \var{identifier}.
Comment on lines +723 to +724
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The \scheme{property-value} procedure is used in macro transformers to look up the value of the
\var{key-identifier} compile-time property of \var{identifier}.
Compile-time properties are not usually available after macro expansion.

If \var{identifier} has no \var{key-identifier} property, \var{default}
is returned.
If omitted, \var{default} defaults to \scheme{#f}.
As the right-hand side of a \scheme{define-property} form is evaluated
at expand-time, note that invoking \scheme{property-value} at relative
run-time within the same library or top-level program won't see the
property.
This is the reason why the \scheme{get-property} macro wrapper around
\scheme{property-value} is used below.
Comment on lines +728 to +733
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this section. I tried to include the essence of the content in the revision above.


If \var{identifier} or \var{key-identifier} have no visible binding,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have => has

an exception with condition type \scheme{&undefined} is raised.

The following example defines a macro, \scheme{get-info}, that retrieves
the \scheme{info} property of a binding, defines the variable \scheme{x},
attaches an \scheme{info} property to the binding of \scheme{x}, retrieves
Expand All @@ -721,11 +747,10 @@ properties are shadowed as well as the outer binding of \scheme{x}.
(define info)
(define-syntax get-info
(lambda (x)
(lambda (lookup)
(syntax-case x ()
[(_ q)
(let ([info-value (lookup #'q #'info)])
#`'#,(datum->syntax #'* info-value))]))))
(syntax-case x ()
[(_ q)
(let ([info-value (property-value #'q #'info)])
#`'#,(datum->syntax #'* info-value))])))
(define x "x-value")
(define-property x info "x-info")
(get-info x) ;=> "x-info"
Expand All @@ -741,10 +766,9 @@ just that.
\schemedisplay
(define-syntax get-property
(lambda (x)
(lambda (r)
(syntax-case x ()
[(_ id key)
#`'#,(datum->syntax #'* (r #'id #'key))]))))
(syntax-case x ()
[(_ id key)
#`'#,(datum->syntax #'* (property-value #'id #'key))])))
Comment on lines +769 to +771
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the original code, because it demonstrates how to use the lookup procedure. Add a note:

This macro can also be defined without the lookup procedure using \scheme{property-value} as in the \scheme{get-info} example above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to my comment above; if we agree that new code probably wants to use property-value, the primary example should be formulated with it. I could add the old version as a secondary example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine with me to have get-info use the lookup procedure and get-property use property-value. I want to have an example of each way.

(get-property x info) ;=> "x-info"
\endschemedisplay

Expand Down Expand Up @@ -810,11 +834,10 @@ cannot be accessed or forged.
(do-drt #'rname #'(fname ...) #f)]
[(_ rname pname (fname ...))
(for-all identifier? #'(rname pname fname ...))
(lambda (lookup)
(let ([prtd (lookup #'pname #'drt-key)])
(unless prtd
(syntax-error #'pname "unrecognized parent record type"))
(do-drt #'rname #'(fname ...) prtd)))]))))
(let ([prtd (property-value #'pname #'drt-key)])
(unless prtd
(syntax-error #'pname "unrecognized parent record type"))
(do-drt #'rname #'(fname ...) prtd)))])))
\endschemedisplay

\schemedisplay
Expand Down
Loading