Just to close out this discussion. The way I proceeded was to finish the 
compile, then invoke the compiled closure (if it did not need any parameters) 
to get the created object. I can then analyze the object to pull out the 
constants needed.

Thanks for all your responses.

On 2020/02/25 09:19:58, Saravanan Palanichamy <chava...@gmail.com> wrote: 
> :D yes which is why I am using the script to gather intent and not using it 
> as the runtime. I need to understand the retry parameters of 10 and 20. I 
> gather this knowledge at the time of creation and compilation which is 
> harmless to exits
> 
> On 2020/02/24 08:15:38, Alessio Stalla <alessiosta...@gmail.com> wrote: 
> > You wouldn't want to run @Retry({System.exit(0)}) on your server, I presume.
> > 
> > On Mon, 24 Feb 2020 at 00:39, Saravanan Palanichamy <chava...@gmail.com>
> > wrote:
> > 
> > >
> > >
> > > On 2020/02/23 23:14:32, Paul King <pa...@asert.com.au> wrote:
> > > > Just for future reference, I'd probably start out with such a question 
> > > > on
> > > > the users mailing list. There are more folks subscribed to that list and
> > > > writing closures and transforms (using Groovy) are topics which that 
> > > > list
> > > > covers. If it turned out that Groovy couldn't handle your use case, the
> > > dev
> > > > list (developing the language) would be the place to go to ask whether a
> > > > feature could be added to the language.
> > > >
> > > > Having said that, to answer your question, there are quite a lot of
> > > > things that are possible. Perhaps you could give a concrete simple
> > > example
> > > > of the kind of thing you are trying to do. I understand most of what you
> > > > are saying but a few bits are still a little unclear (to me at least).
> > > >
> > > > Cheers, Paul.
> > > >
> > > >
> > > > On Mon, Feb 24, 2020 at 9:06 AM Saravanan Palanichamy <
> > > chava...@gmail.com>
> > > > wrote:
> > > >
> > > > > Hello
> > > > >
> > > > > Is it possible to do this in the groovy AST transformation ->
> > > > >
> > > > > a) in a code visitor, visit a closure expression (in the
> > > > > INSTRUCTION_SELECTION phase)
> > > > > b) Using the Closure Node, execute this code to determine its results
> > > > > based on different parameters
> > > > >
> > > > > Essentially I want to be able to selectively run a closure defined in
> > > code
> > > > > during the compile process. I see you can convert closures into
> > > strings, is
> > > > > it possible to compile that string in the middle of a compile process?
> > > > >
> > > > > I am not sure this is the right forum for this question, please let me
> > > > > know if otherwise
> > > > >
> > > >
> > >
> > > Hello Paul
> > >
> > > Thank you for your reply. I am trying to do this specific thing
> > > a) I allow my developers to write Groovy scripts
> > > b) I use the script as a DSL to generate actual configuration files needed
> > > for my service at runtime.
> > > c) Because I need to translate the code to configuration entries, I need
> > > to execute some parts of the script to determine config values. For 
> > > example
> > >
> > > @Retry({new RetryParams(10, 20)})
> > > void runSomeCodeInMyServer() {
> > > }
> > >
> > > In the code above, lets say this code runs on my server, but the server
> > > needs to be told that the parameters for the thread that executes this is
> > > to retry it 10 times, with a 20 second interval.
> > >
> > > When parsing the groovy script, I need to pull out these 10 and 20 numbers
> > > from the script. One way to do this is visit the closure, see this was a
> > > constructor call to RetryParams, and use the numbers there. This seems
> > > tedious given the number of combinations possible. However if there was 
> > > way
> > > for me to run this closure during the AST transform, I can inspect the
> > > created retryparams object to get my values. Does that make sense?
> > >
> > > As I am typing this, I also realize that the closure may call other
> > > functions which may need to be compiled as well (but I can create compile
> > > errors there to keep it simple)
> > >
> > 
> 

Reply via email to