Storing code for later evaluation at runtime

Hi,

I'm constructing a struct/dc contract through a macro.

The real contract specs would only be known at struct instantiation time late into execution, and I need to store the original contract and modify it according to the new specs. I could store the contract as a quoted list, modify it and use eval.

However, racket has the concept of 'syntax fragments', that I understand very little about. Is the right way to do what I need in Racket to keep the original struct/dc contract as syntax instead of a quoted list and modify that?

Sorry if this doesn't make sense, I'm struggling a bit (lot).

An example of what you are trying to do would be helpful. What is an example of the initial contract? What is an example of the modified contract?

It’s likely that eval might not be necessary, and there might be a better approach.

2 Likes

I agree with @sorawee. In particular, you speak of the need to construct contracts that depend on information not available until later. Since contracts can be arbitrary predicates, this can easily be done with mutation, without the need for eval. Indeed, it might be possible to do it without mutation, as well; it would be great to hear more about the situation you're in.