Syntax ideas for the next version of RiveScript|Kirsle|casey@cuvou.net|1329325472|Kirsle|xx|0|72.37.252.50|RiveScript is pretty flexible but it can tend to be difficult to write complicated replies (if you have conditionals and you also want random responses for each condition... or if you simply want to stack conditions up, you can't do this). We end up having to write ugly looking code like:<br /><br />[code]+ my name is *<br />* &lt;get name&gt; == &lt;formal&gt; =&gt; I know, you've\s<br />   ^ told me your name before.<br />* &lt;get name&gt; == &lt;bot name&gt; =&gt; &lt;set name=&lt;formal&gt;&gt;&#123;random&#125;<br />   ^ Wow, we have the same name!&#124;<br />   ^ What a coincidence, that's my name too!&#124;<br />   ^ What are the odds that we'd have the same name?<br />   ^ &#123;/random&#125;<br />- &lt;set name=&lt;formal&gt;&gt;Nice to meet you, &lt;get name&gt;![/code]<br /><br />Wouldn't this ugly code look much nicer if the syntax were more like this?<br /><br />[code]trig my name is *<br />    if (&lt;get name&gt; == &lt;formal&gt;) &#123;<br />        reply I know, you've told me your name before.<br />    &#125;<br />    elsif (&lt;get name&gt; == &lt;bot name&gt;) &#123;<br />        set name = &lt;formal&gt;<br />        random &#123;<br />            Wow, we have the same name!<br />            What a coincidence, that's my name too!<br />            What are the odds that we'd have the same name?<br />        &#125;<br />    &#125;<br />    else &#123;<br />        set name = &lt;formal&gt;<br />        reply Nice to meet you, &lt;get name&gt;!<br />    &#125;[/code]<br /><br />This sort of syntax wouldn't be backwards compatible, however, so this would call for a new RiveScript 3.0 version of the language. Here is a mockup of what it might look like. Any thoughts/suggestions are welcome.<br /><br />[code]// RiveScript 3.0 syntax mockup<br /><br />! version = 3.0<br /><br />// Same syntax as RS 2.0<br />! array colors = red green blue yellow<br />! sub who's = who is<br /><br />// The new version of the &gt; begin block<br />begin &#123;<br /> &nbsp; &nbsp; &nbsp;// New version of conditionals<br /> &nbsp; &nbsp; &nbsp;if (&lt;get name&gt; == undefined) &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// New way of setting vars, the &lt;set&gt; tag is removed<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set topic = newuser<br /> &nbsp; &nbsp; &nbsp;&#125;<br /><br /> &nbsp; &nbsp; &nbsp;if (&lt;bot mood&gt; == normal) &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// The reply commands stack, more than one reply = they concatenate.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply &lt;ok&gt;<br /> &nbsp; &nbsp; &nbsp;&#125;<br /> &nbsp; &nbsp; &nbsp;elsif (&lt;bot mood&gt; == angry) &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// No more difference between &#123;tags&#125; and &lt;tags&gt;, we use &lt;tags&gt; everywhere<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply &lt;uppercase&gt;&lt;ok&gt;&lt;/uppercase&gt;<br /> &nbsp; &nbsp; &nbsp;&#125;<br /> &nbsp; &nbsp; &nbsp;elsif (&lt;bot mood&gt; == sad) &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply &lt;lowercase&gt;&lt;ok&gt;&lt;/lowercase&gt;<br /> &nbsp; &nbsp; &nbsp;&#125;<br />&#125;<br /><br />topic newuser &#123;<br /> &nbsp; &nbsp; &nbsp;// Maybe + will be an alias for trig? And - an alias for reply?<br /> &nbsp; &nbsp; &nbsp;// Triggers make &quot;implied&quot; blocks (no need for &#123; and &#125;). The block ends<br /> &nbsp; &nbsp; &nbsp;// when a new trigger is found or a parent block ends (a &#125; is found).<br /> &nbsp; &nbsp; &nbsp;trig *<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set topic = newuser_1<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply Hello, I don't know you! What's your name?<br />&#125;<br /><br />topic newuser_1 &#123;<br /> &nbsp; &nbsp; &nbsp;// Wildcards are the same: _ for words, # for numbers, * for anything<br /> &nbsp; &nbsp; &nbsp;trig my name is _<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set name = &lt;formal&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set topic = newuser_2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply Nice to meet you, how old are you?<br /><br /> &nbsp; &nbsp; &nbsp;// 'alias' is the new @.<br /> &nbsp; &nbsp; &nbsp;trig _<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alias my name is &lt;star&gt;<br /><br /> &nbsp; &nbsp; &nbsp;trig *<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply I'm sorry, what was your name?<br />&#125;<br /><br />topic newuser_2 &#123;<br /> &nbsp; &nbsp; &nbsp;trig i am # years old<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set age = &lt;star&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set topic = random<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply Ok, I will remember you are &lt;get age&gt; years old.<br /><br /> &nbsp; &nbsp; &nbsp;trig #<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alias i am &lt;star&gt; years old<br /><br /> &nbsp; &nbsp; &nbsp;trig *<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply I'm sorry, how old are you?<br />&#125;<br /><br />// The indentations are optional but recommended for style<br />trig hello bot<br />reply Hello human!<br /><br />// aliases can stack with replies.<br />trig * or something<br /> &nbsp; &nbsp; &nbsp;reply Or something.<br /> &nbsp; &nbsp; &nbsp;alias &lt;star&gt;<br /><br />// Random replies. To continue a line, end it with a \ character.<br />// The random keyword stacks with reply too.<br />trig how are you<br /> &nbsp; &nbsp; &nbsp;random &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;I'm great, how are you?<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Good, you?<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;I'm doing well, how about you?<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;I am doing so well you \<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wouldn't even believe it.<br /> &nbsp; &nbsp; &nbsp;&#125;<br /><br />// A reply stacking example. Replies are concatenated using space characters<br />// now (this may be a configurable option which may be dynamically changed)<br />trig tell me about linux<br /> &nbsp; &nbsp; &nbsp;// Begin a reply.<br /> &nbsp; &nbsp; &nbsp;reply Linux is a free operating system.<br /><br /> &nbsp; &nbsp; &nbsp;// Set some variables.<br /> &nbsp; &nbsp; &nbsp;set topic = linux<br /><br /> &nbsp; &nbsp; &nbsp;// Continue.<br /> &nbsp; &nbsp; &nbsp;reply It was written by Linus Torvalds and first released in 1991. \<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;One example of a distribution of Linux is<br /><br /> &nbsp; &nbsp; &nbsp;// A bit of random<br /> &nbsp; &nbsp; &nbsp;random &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Fedora.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Ubuntu.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Gentoo.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Mandriva.<br /> &nbsp; &nbsp; &nbsp;&#125;<br /><br /> &nbsp; &nbsp; &nbsp;// Throw in a conditional.<br /> &nbsp; &nbsp; &nbsp;if (&lt;get name&gt; == Linus) &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply You have the same name as the creator of Linux!<br /> &nbsp; &nbsp; &nbsp;&#125;<br /><br />// You can redefine global variables just as easily now too.<br />trig turn debugging (on&#124;off)<br /> &nbsp; &nbsp; &nbsp;// Only the botmaster!<br /> &nbsp; &nbsp; &nbsp;if (&lt;id&gt; == &lt;bot master&gt;) &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (&lt;star&gt; == on) &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Variables are lexically scoped to the current request.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var debug = true<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var debug = false<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Set the debug mode.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;! global debug = &lt;var debug&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply Debugging has been turned &lt;star&gt;.<br /> &nbsp; &nbsp; &nbsp;&#125;<br /> &nbsp; &nbsp; &nbsp;else &#123;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reply You are not the botmaster. I won't listen to you.<br /> &nbsp; &nbsp; &nbsp;&#125;<br /><br />// Object example.<br />object md5_encode perl &#123;<br /> &nbsp; &nbsp; &nbsp;my ($rs, @args) = @_;<br /><br /> &nbsp; &nbsp; &nbsp;use Digest::MD5 qw(md5_hex);<br /> &nbsp; &nbsp; &nbsp;my $hash = md5_hex(join(&quot; &quot;, @args));<br /><br /> &nbsp; &nbsp; &nbsp;return $hash;<br />&#125;<br /><br />// Call the object example.<br />trig what is the md5 hash of *<br /> &nbsp; &nbsp; &nbsp;// If the character(s) used to concatenate reply segments is configurable,<br /> &nbsp; &nbsp; &nbsp;// it could be overridden on a per-reply basis. Here we could set it to<br /> &nbsp; &nbsp; &nbsp;// be a blank string. BTW, quotes can be optionally used on all &quot;set&quot; like<br /> &nbsp; &nbsp; &nbsp;// commands, but are optional. They're handy for setting empty strings or<br /> &nbsp; &nbsp; &nbsp;// spaces as values though.<br /> &nbsp; &nbsp; &nbsp;option concat = &quot;&quot;<br /><br /> &nbsp; &nbsp; &nbsp;reply The MD5 hash of &quot;&lt;star&gt;&quot; is &quot;<br /> &nbsp; &nbsp; &nbsp;call md5_encode &lt;star&gt;<br /> &nbsp; &nbsp; &nbsp;reply &quot;.[/code]||||
Re: Syntax ideas for the next version of RiveScript|79b.org|planet8@rocketmail.com|1329453186|79b.org|xx|0|108.5.43.133|It is twice the lines of code, the new format.||||
Re: Syntax ideas for the next version of RiveScript|calyx|calyx238@gmail.com|1363825050|calyx|xx|0|87.112.4.107|I like the proposed syntax. Much more readable, and stacked conditionals would be awesome. I hope one day you have time to work on this.||||
Re: Syntax ideas for the next version of RiveScript|Kirsle|casey@cuvou.net|1363838294|Kirsle|xx|0|76.168.88.125|I've been doing some more thinking on this lately and I think a Python-style syntax might look cleaner. So there wouldn't be so many brackets. ;) Something along the lines of...<br /><br />[code]on hello bot:<br />   say Hello, human!<br /><br />on my name is *:<br />   set name = &lt;star&gt;<br />   say Nice to meet you, &lt;get name&gt;!<br /><br />on what is my name:<br />   if defined name:<br />      say Your name is &lt;get name&gt;, seeker!<br />   else:<br />      say I don't know what your name is.<br /><br />on say something random:<br />   say This<br />   random [<br />     &quot;sentence&quot;,     &quot;message&quot;,<br />   ]<br />   say has a random<br />   random [<br />     &quot;couple of words&quot;,     &quot;few things&quot;,<br />   ]<br />   say in it.[/code]<br /><br />I'm still playing around with some syntax ideas. The idea of quoting the parameters sounds cool, but it looks a bit ugly when you have a character like * at the end of a quoted string, like &quot;my name is *&quot;... and for readability, I may make colons optional after the commands, and optional at the ends of some lines, so:<br /><br />[code]on: my name is *<br />   say: Nice to meet you![/code]||||
Re: Syntax ideas for the next version of RiveScript|calyx|calyx238@gmail.com|1363901733|calyx|xx|0|87.112.4.107 87.114.141.144|Good to hear you're still working on this. I'm a Perl programmer, but I agree that the Python syntax looks cleaner for this.<br /><br />I like the colon after the command syntax. It means there is no ambiguity which words are commands, for example:<br /><br />on on the yygffd<br />    say say that again?<br /><br />I will gladly help you test when you have a draft.  :)||1363920852|calyx|
