Summary

defstruct could use compiler-syntax to speed up instance creation

Metadata

Description

By defining a compiler-macro on the constructor, keyword arguments can be pre-parsed and the constructor call be replaced by a direct structure value construction. Since this is applicable to various procedures, a general library procedure might be handy:

(unit `eval`)

 (parse-keyword-arguments ARGLIST KEYS+DEFAULTS K) -> FORM

where K is a procedure `TMPVARS -> BODY` that returns a body. `FORM` is then a `let*` form binding temporaries to keep the original evaluation order of the arguments. In case of an invalid keyword argument list (computed keyword, missing keyword argument, non-keyword in keyword position, etc.) `parse-keyword-arguments` returns `#f`.

Changes and comments

[2010-05-20 17:51:08 UTC] felix wrote:

Added `##sys#parse-keyword-argument-list` in 8f79e95e7a50a216f1c46e472263d566ef06de66 (experimental).

[2010-05-22 00:17:54 UTC] felix wrote:

Replying to felix: > Added `##sys#parse-keyword-argument-list` in 8f79e95e7a50a216f1c46e472263d566ef06de66 (experimental).

... and removed it again. It is better placed inside the defstruct code or into a separate extension.

[2010-05-22 14:22:31 UTC] felix changed status from new to closed

[2010-05-22 14:22:31 UTC] felix set resolution to wontfix

[2010-05-22 14:22:31 UTC] felix wrote:

No easy implementation: `defstruct` has to expand into a compiler-syntax definition that must pass a list of keywords and default arguments, but those arguments are quoted in the definition and will lose renaming information.

Currently not worth the trouble.