Dylan Reference Manual questions 
Author Message
 Dylan Reference Manual questions

[Q] In the second paragraph on page 145, the Dylan Reference Manual states:

  "The compiler delays computing the expansion of a macro call fragment
until needed. If an argument to a macro is a macro call, the outer macro is
always expanded first..."

Does this make any difference? Why couldn't a parser expand a macro as soon
as it saw the ending token? (This would cause macros to be expanded in
reverse order--inner ones first.)

A nested macro is a "macro call fragment," which is an elementary fragment
insofar as any surrounding macros are concerned. If inner macro was
expanded first--and marked as an expanded macro call, so as not confuse
macro pattern variables with ":macro" constraints--would anything break?

[Q] What's the deal with "cerror" on page 359? The parameter lists don't
match the descriptive text underneath.

[Q] On page 362, "restart-query" is documented as returning any number of
values of type <object>. What are these, and what would they be used for?

[Q] The table protocol, as described on pages 122 and 123, mentions
something called a "hash state":

  "A hash state is an object of implementation-dependent type that is
associated with a particular hash id and can be used by the implementation
to determine whether the hash id has been invalidated."

As far as I can tell, there's only three ways for a custom hash function to
create a hash state:

 * Call object-hash, and use the returned hash state
 * Call merge-hash-codes, and use the returned hash state
 * Return $permanent-hash-state

What are these mysterious beasties? Does anyone have examples of custom
hash functions written in portable Dylan?

My many thanks to anyone who can enlighten me in these matters.

Cheers,
Eric

http://www.*-*-*.com/ ~emk/



Thu, 15 Jul 1999 03:00:00 GMT  
 Dylan Reference Manual questions

Quote:

> Date: Sun, 26 Jan 1997 04:48:40 -0500

> [Q] In the second paragraph on page 145, the Dylan Reference Manual states:

>   "The compiler delays computing the expansion of a macro call fragment
> until needed. If an argument to a macro is a macro call, the outer macro is
> always expanded first..."

> Does this make any difference? Why couldn't a parser expand a macro as soon
> as it saw the ending token? (This would cause macros to be expanded in
> reverse order--inner ones first.)

> A nested macro is a "macro call fragment," which is an elementary fragment
> insofar as any surrounding macros are concerned. If inner macro was
> expanded first--and marked as an expanded macro call, so as not confuse
> macro pattern variables with ":macro" constraints--would anything break?

No, that won't work.  The reason is that it isn't until the outer macro is
expanded that the meaning of the inner thing can be determined.  It could be
that the subform that looks like a macro call is actually a bunch of tokens
that get scattered to various places in the expansion of the outer macro, and
so actually aren't a macro call at all.

Quote:
> [Q] What's the deal with "cerror" on page 359? The parameter lists don't
> match the descriptive text underneath.

I looked, and don't understand the question.  Could you be more specific?

- Show quoted text -

Quote:
> [Q] On page 362, "restart-query" is documented as returning any number of
> values of type <object>. What are these, and what would they be used for?

> [Q] The table protocol, as described on pages 122 and 123, mentions
> something called a "hash state":

>   "A hash state is an object of implementation-dependent type that is
> associated with a particular hash id and can be used by the implementation
> to determine whether the hash id has been invalidated."

> As far as I can tell, there's only three ways for a custom hash function to
> create a hash state:

>  * Call object-hash, and use the returned hash state
>  * Call merge-hash-codes, and use the returned hash state
>  * Return $permanent-hash-state

That's correct.

Quote:
> What are these mysterious beasties?

A hash state provides the mechanism for informing the table implementation
whether the associated hash id was based on the address of some objects, and
if so, might provide some additional information about those addresses.
(The pluralized "objects" and "addresses" in the preceding sentence is to
account for merge-hash-codes.)  The table implementation can then conspire
with the garbage collector to notice that a hash id has been invalidated
because the garbage collector has moved (some of) the objects, and perhaps
rehash the table.

Some plausible implementations of hash states returned by object-hash include:

 - With a non-transporting garbage collector, just use $permanent-hash-state.

 - With a 2-space copying collector, use a count of the number of gc's.
   merge-hash-codes returns the minimum of the argument states.
   $permanent-hash-state is recognizably "larger" than any possible count
   (perhaps it is #f, with appropriate handling by the state minimization).

 - With a generational collector, number the generations from 0 to n and
   set the bit corresponding to the generation in which the object is
   currently located.  merge-hash-codes logior's the argument states to
   compute the result state.

These examples should be considered illustrative; they are not exhaustive
either in the set of possible gc implementations nor in the possible state
implementations associated with a given gc implementation.  Don't even
assume these are "good" (as in efficient) implementations; they are just
some possibilities that I thought I could describe reasonably succinctly.

Quote:
> Does anyone have examples of custom hash functions written in portable Dylan?

I thought there was at least one example in the "Dylan Programming" book,
but I couldn't find one with just a quick look.  I've got some examples
around someplace but couldn't find them quickly either.  If nobody else
responds soon, I'll come up with something.


Fri, 16 Jul 1999 03:00:00 GMT  
 Dylan Reference Manual questions


Quote:

>> Does anyone have examples of custom hash functions written in portable Dylan?

>I thought there was at least one example in the "Dylan Programming" book,
>but I couldn't find one with just a quick look.  I've got some examples
>around someplace but couldn't find them quickly either.  If nobody else
>responds soon, I'll come up with something.

Apple Dylan TR includes an example library which implements one or two
custom hash tables.  They are quite simple.  I'd post the text of them,
but I don't have the TR installed.  Perhaps someone else who does could
do so.

--
Andrew Shalit                              Time is a meadow, not a highway.
http://www.shore.net/~alms                                    -Tom Robbins



Fri, 16 Jul 1999 03:00:00 GMT  
 Dylan Reference Manual questions

Quote:

> Does anyone have examples of custom hash functions written in
> portable Dylan?

define class <resource-table> (<object-table>)
end;

define method table-protocol(t :: <resource-table>)
  => (test-function :: <function>, hash-function :: <function>);
  values(\=, resource-hash)
end;

define method resource-hash(r :: <raw-resource-id>)
  object-hash(r.pointer-address)
end;



Fri, 16 Jul 1999 03:00:00 GMT  
 Dylan Reference Manual questions


Quote:
>> Does anyone have examples of custom hash functions written in portable
>>Dylan?

>I thought there was at least one example in the "Dylan Programming" book,
>but I couldn't find one with just a quick look.

p. 386, but there is little explanatory text.  Custom tables were
considered too advanced for an introductory book.  The example cited is
intended to pique the reader's curiosity.


Fri, 16 Jul 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Book FS: Dylan Reference Manual, by Andrew Shalit.

2. How update of Dylan reference manual?

3. How update of Dylan reference manual?

4. Dylan Reference Manual and MacWorld

5. Dylan Reference Manual online now

6. Dylan Interim Reference Manual now available

7. Dylan Interim Reference Manual now available

8. Dylan Reference Manual

9. Posting Apple's Dylan Ref Manual?

10. Dylan Manual

11. Dylan ref manual sighting

12. Dylan manual as postscript file?

 

 
Powered by phpBB® Forum Software