On 2006-05-26, Michaƫl Cadilhac michael.cadilhac@lrde.org wrote:
SIGOURE Benoit sigoure.benoit@lrde.epita.fr writes:
https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog from SIGOURE Benoit sigoure.benoit@lrde.epita.fr
Add the rand() builtin.
- src/lib/xrm/pp/xrm-expression.str: Add boxing for the rand builtin.
- src/str/xrm-to-prism.str: Split xrm-to-prism-desugar in several rules. Add rand(N) and rand(from, to) builtin.
- src/str/ice.str: Add not-implemented() strategy.
- src/str/eval-meta-code.str: Nothing.
- src/syn/xrm/XRM-Expression.sdf: Add the rand builtin.
- src/syn/prism/PRISM-MetaVars.sdf: Add a meta-var.
- src/syn/prism/StrategoPRISM.sdf: Ditto.
- tests/xrm/rand.xpm: New.
- tests/prism/formula.pm: New.
- TODO: Update.
Marvelous, thanks a lot ! Et mes amities =E0 ta copine ! ;-)
Hmm y'a un bug dans ce commit :)
rand(low, hi) produit un chiffre aleatoire entre low et high (inclus) donc chaque chiffre a une probabilite de sortir qui est de 1/(high-low+1) et non pas 1/(high-low) comme je l'ai fais ici.
Ce bug est fixed dans ma working copy a la maison, et il viendra avec la revision 42 \o/ la revision magique
en attendant:
Index: src/str/xrm-to-prism.str =================================================================== --- src/str/xrm-to-prism.str (revision 41) +++ src/str/xrm-to-prism.str (working copy) @@ -111,10 +111,8 @@ " arguments must be statically evaluable"]) ; !current-term; debug; <xtc-exit> 4 end - ; <debug> ifrom - ; <debug> ito ; <newname> "__rand" => rand-var - ; !ProbUpdate( Div(Int("1"), Int( <subtS>(ito, ifrom) )) + ; !ProbUpdate( Div(Int("1"), Int( <addS>(<subtS>(ito, ifrom), "1") )) , UpdateList([UpdateElement(IdentifierPrime(rand-var), FIXME())])) ; {| RandUpdateList: for-loop(gen-rand-update-list | ifrom, ito, "1", [])