Joel Uckelman on Sun, 17 Dec 2006 14:50:24 -0700 (MST)

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [s-d] dice server enhancements

Thus spake Daniel Lepage:
> Language features I would like:
> 1. Array indices. For example,
> ==
> {{let x = 3#d5 in x[1]+x[2] - x[3]}}
> ==
> x[i] is syntactic sugar for "last 1 first i x".
> 2. Global variables. For example,
> ==
> {{let x = sum 3#d5 in everything}}
> Wonko gains {{x}} points and loses {{x/2}} Charisma.
> ==
> This has two major benefits.
> 1) It solves the problem of referring to earlier rolls, as in "{{let  
> x = 3#d5 in everything}} Wonko gains {{x[1]}} + {{x[2]}} + {{x[3]}} =  
> {{sum x}} points."
> 2) It allows you to put in a bunch of constants to start off your  
> script, e.g.
> ==
> {{let weapons = ("Sword of Truth","Spear of Lies","Axe of  
> Kindness","Prong of Tickles") in everything}}
> later...
> Wonko gets a {{first 1 perm weapons }}.
> ==
> 3. Assignment lists. For example,
> ==
> {{
> let x=1d5, y=2d x in (x+y,x-y)
> }}
> ==
> This is syntactic sugar for
> ==
> {{
> let x = 1d5 in let y = 2d x in (x+y,x-y)
> }}
> ==
> 4. Some sort of bottled expression syntax, like code blocks in Ruby,  
> or even just like functions in other languages. For example,
> ==
> {{define choose_weapon = first 1 perm weapons in everything}}
> Wonko gets a {{choose_weapon}} and a {{choose_weapon}}. /* The two  
> weapons could differ */
> ==
> 5. Some sort of textual if-else? For example, suppose I need to roll  
> some dice, and the outcome determines whether I live or die. If I  
> live, then a set of rolls needs to be made to determine by how much;  
> if I die, then a different set of rolls needs to be made to determine  
> how I am reborn. Ideally, whole blocks of text and instructions would  
> be kept or thrown out depending on these rolls. An example:
> ==
> {{
> let wonko_dies = > 4 d6 in
> 	if wonko_dies then
> }}
> Wonko dies. E is trapped in limbo for {{2d3}} ndays, and will emerge  
> then on square ({{d20}},{{d20}}).
> {{
> 	else
> }}
> Wonko survives the attack. E gains {{4d3+1d2}} experience and finds a  
> {{ first 1 perm("Sword","Axe","Stick")}} of {{ first 1 perm 
> ("Smiting","Power","Suckiness") }}.
> ==
> I tried a few months ago to write a python-based dice rolling  
> language that had this feature, and being unable to come up with a  
> good way to handle this was really what killed the project (well,  
> that and prelims). The two ideas I had were first to do it as above,  
> where ifs and elses can just contain the end-of-code delimiter and  
> the resulting text becomes part of the conditional, and second to do  
> it with special penup and pendown functions that would disable and re- 
> enable the production of text. But neither is a very clean solution.
> -- 
> Wonko

It sounds like what you want is "text mode" and "code mode", combined with
statefulness for the interpreter over the whole message. 

What would you think of having something which is more or less a subset
of C or Perl, with all of the special die-rolling functions as built-ins?

So, you'd do this:

   if (d6 > 4) {{Wonko dies. E is trapped in limbo for {{2d3}} ndays, and will emerge then on square ({{d20}},{{d20}}).}}
   else {{Wonko survives the attack. E gains {{4d3+1d2}} experience and finds a {{perm("Sword","Axe","Stick")[0]}} of {{perm("Smiting","Power","Suckiness")[0]}}

Or something like it. The default mode would be text, and each set of braces
toggles to the opposite mode. You'd also have a positional variable $n,
corresponding to the output of the nth invocation of code mode.

I'd drop the 'let' from assignment, so you'd have {{ x = 5 }}, like in any
normal language. Array indices would be easy, just suffix [i] onto any list.

The "return" value of a code block {{ }} would be the value of the last
expression to appear in it. I'm not sure what to do about blocks where you
don't want a return value, e.g., where you're doing some setup. That could
be done by having a 'silent' operator:

{{ silent x = 5 }}

or just by ending such blocks with an empty list:

{{ x = 5 ; () }}

We could define functions like this:

{{ sub foo(x,y,z) { x + y + z } }} 
I drink {{ foo(d6,1,4d3) }} shots of tequilla.

More comments?

(Sorry for spilling all of this stuff onto the game list, for those of
you who don't care about the minutae.)

spoon-discuss mailing list