[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using guile like a awk filter in a C program.
From: |
Simon Tournier |
Subject: |
Re: using guile like a awk filter in a C program. |
Date: |
Fri, 17 May 2024 20:09:20 +0200 |
Hi,
On Fri, 10 May 2024 at 15:55, Pierre LINDENBAUM
<Pierre.Lindenbaum@univ-nantes.fr> wrote:
> ```
> header = read_header(input);
> guile_context = my_initialize_guile(header, argc_argv_user_script)
> variant = new_variant();
> while(read_variant(input,header,variant)) {
> if(!my_guile_test(guile_context,header,variant)) {
> continue;
> }
> do_something(header,variant)
> }
> dispose_variant(variant)
> my_dispose_guile(guile_context)
> dispose_header(header)
> ```
>
> and would may be be invoked like:
>
> ```
> ./a.out -e '(and (variant-is-snp? ) (equals? (variant-allele-count) 2))'
> input.vcf > output.vcf
> ```
[...]
> - is it possible to use guile for such task ? More precisely, can I
> compile the guile script just once in `my_initialize_guile` and use it
> in the while loop without having to recompile it.
I am not sure to well understand. Since, it could be read two ways:
+ Call Scheme from C
+ Call C from Scheme
Will the main loop be in C-like or in Guile?
> - furthermore, what's the best practice to include the user's script in
> a larger script that would include the definitions of `variant-is-snp?`
> , `variant-allele-count`, etc...
Maybe modules?
> - is there any implementation that works like this (something like a AWK
> script in guile) ?
What you want to replace is the driver – currently implemented in AWK.
You would like to have the driver (glue code) in Guile. Is it correct?
> - is there any way to make the program stateless ? I mean, any
> invocation of `my_guile_test` would erase the definition of the previous
> variant
Well, this question depends on the above, I guess. :-)
Cheers,
simon