Description
This article is from the FAQ, by with numerous contributions by
others.
F03) How do I work around "Only pattern-declarations may appear in a fragment of category 'attributes'"?
In F02, we didn't get rid of the i, j, and r implementation attributes of f.
The reason is that it is not possible to do the most obvious, which would
have been the following:
fSource.bet:
ORIGIN '...';
BODY 'fBody'
--- lib: attributes ---
f: (# t: @text;
<<SLOT fLib: attributes>>
enter t[]
<<SLOT fBody: dopart>>
#)
fBody.bet:
ORIGIN 'fSource'
--- fLib: attributes ---
i,j: @integer; r: @real
--- fBody: dopart ---
do (* ... some code implementing f ... *)
since it is not allowed to specify reference attributes (static or dynamic)
in attribute slots.
Instead we have to use the following trick:
fSource.bet:
ORIGIN '...';
BODY 'fBody'
--- lib: attributes ---
f: (# t: @text;
fPrivate: @<<SLOT fLib: descriptor>>
enter t[]
<<SLOT fBody: dopart>>
#)
fBody.bet:
ORIGIN 'fSource'
--- fLib: descriptor ---
(# i,j: @integer; r: @real #)
--- fBody: dopart ---
do (* ... some code implementing f ... *)
and in (* ... some code implementing f ... *) we have to change all
references to i, j, and r to fPrivate.i, fPrivate.j, and fPrivate.r.
 
Continue to:
Share and Enjoy
Bookmark this story so others can enjoy it:
Tags
programming