2009/9/17 Joe Groff <[email protected]>:
> On Sep 17, 2009, at 11:53 AM, Paul Moore wrote:
>
>> The background is that I'm playing with ideas around game simulation
>> programs, where die rolls are a common need. I can obviously write a
>> word dieroll ( n m -- roll ) to roll n m-sided dice and produce a
>> result - but where n and m are literals (as they often are) the usual
>> syntax is nDm (for example, 3D6) and it'd be nice to be able to
>> express that directly in Factor.
>
> The way to do this is to define a syntax word prefix, so your literals
> would look something like "ROLL: 3D6". Your "ROLL:" syntax word can
> then read whatever syntax it wants from the incoming source code stream.

Sorry, I didn't explain clearly - I was aware of defining words and
the possibility of doing something like this. What I was thinking of
was more along the lines of the way fractions are supported - in

3/4 2/7 + .

you don't need to predeclare the fractions 3/4 and 2/7. Rather, the
parser, on seeing that these are not predefined words, passes them to
the number formatting routines (specifically string>number) which
build a fraction on the fly. In much the same way, I'd like to define
my own parse-time special forms.

Look at it another way - if the 3/4 rational number syntax wasn't
already part of factor, would I be able to add it in user code? The
fact that the syntax isn't defined in math.ratio, implies to me that
the answer is "no".

Actually, my idea wouldn't work in practice - as 3d6 is intended to be
a random number, it isn't actually a literal at all! So my intended
use wouldn't work. But I'm still interested in whether it's possible
to do this, from a theoretical standpoint.

Paul.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to