> On 19 Jul 2022, at 04:28, Fabrice L via ntg-context <ntg-context@ntg.nl> 
> wrote:
> 
> Complementary question : I saw that the « pos_a » « pos_b » of the example 
> could not take numerical value, for example pos_1, pos_2.. How can I use 
> metafun to write a macro to save the contents of hundreds of variable in this 
> object, something like :
> 
> getparameters "MyData » [
>       for i=1 upto 100 :
>               pos_decimal(i) = ThePosition[i],
>       endfor ;
> ] ;
> 
> If this is possible, then this is wonderful and open news doors ! 

I've adapted this example from the metafun-p manual by adding some "write" 
statements.

\starttext
\startMPpage
      
numeric done[][], i, j, n ; n := 0 ;
forever :
        i := round(uniformdeviate(10)) ;
        j := round(uniformdeviate(10)) ;
        if unknown done[i][j] :
                drawdot
                        (i*cm,j*cm)
                        withpen pencircle scaled 0.5cm
                        withcolor darkred;
                n := n + 1 ;
                done[i][j] := n ;
                
                write "done[" & tostring(i) & "][" & tostring(j) & "] := " & 
tostring(n) & " ;" to "mp_test_file.txt" ;

        fi ;
        exitif n = 10 ;
        
endfor ;

write EOF to "mp_test_file.txt" ;
   
\stopMPpage
\stoptext

This results in the expected graphic but also a local file (in the same 
directory as the source) called "mp_test_file.txt" that contains:

done[9][1] := 1 ;
done[4][3] := 2 ;
done[5][3] := 3 ;
done[5][1] := 4 ;
done[2][9] := 5 ;
done[8][6] := 6 ;
done[9][10] := 7 ;
done[9][7] := 8 ;
done[10][2] := 9 ;
done[6][5] := 10 ;

I think, with a bit of judicious use of "write" statements to add some ConTeXt 
/ MP setup code, it would be possible to include the output from the previous 
run as MP source of the next run.

Hope this helps, or at least provides some food for thought.

(Note you need to delete the mp_test_file.txt before re-running else it fails.)

—
Bruce Horrocks
Hampshire, UK

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

Reply via email to