Pattern-matching with views [1,2], anyone ?
Cheers,
David
[1] http://martin.jambon.free.fr/micmatch-manual.html#htoc10
[2] http://blogs.msdn.com/dsyme/archive/2006/08/16/ActivePatterns.aspx
On Tue, 2007-10-16 at 20:11 +0200, liorean wrote:
> On 16/10/2007, Peter Hall <[EMAIL PROTECTED]> wrote:
On 16/10/2007, Peter Hall <[EMAIL PROTECTED]> wrote:
> already you can do something like this:
>
> var str;
> switch(true){
> case /a/.test(str):
> alert('a');
> break;
> case /b/.test(str):
> alert('b');
> break;
> }
I can only imagine that solution being preferable to chained
if..else-st
On Oct 16, 2007, at 8:19 AM, Dave Herman wrote:
> But that's not what you proposed, is it? I understood your proposal to
> mean something more like:
>
> function f(g) {
> if (let (tmp = g())// case g():
> (tmp is RegEx ? tmp.match(x) : x == tmp))
> if
> }
>
> Dave
Minor nitpick, but that should be "===" not "==".
I really like the idea, but probably it should be done in a way that
could be generalised beyond just the RegExp case. And that doesn't
seem like something that can be done in the es4 time-frame.
But already you can do something like this:
var st
[ snip ]
> Sure. From what I can see of the Microsoft documentation a
> standardized String.format() function would meet the need for a
> standardized way of formatting a string just as well as a method
> based on C/Perl/PHP/Ruby sprintf() and Python's native string
> formatting, where named param
But that's not what you proposed, is it? I understood your proposal to
mean something more like:
function f(g) {
if (let (tmp = g())// case g():
(tmp is RegEx ? tmp.match(x) : x == tmp))
if
}
Dave
[EMAIL PROTECTED] wrote:
> I think switch ... case construction m
I think switch ... case construction must be interpreted as:
function f(g) {
if( x == g() ) // case g():
if( // case ...
}
- Original Message -
From: "Dave Herman" <[EMAIL PROTECTED]>
To: "Lars T Hansen" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>;
Se
It's clever, but it's a special case that may not abstract very
smoothly. For example:
function f(g) {
switch (x) {
case g():
...
}
}
The behavior of my function depends on whether g() returns a RegEx or a
non-RegEx. Maybe that's what you want, but it means it's an e
On 16/10/2007, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> In the next line there is ambigious between RegEx and comment
> str.match(//);
Not really. // is always a line comment starter in ES3:
7.8.5 Regular Expression Literals
/- - -/
NOTE Regular expression literals may not be empt
I would be all for .NET's String.Format() style of formatting. Adobe Flex
provides a similar method in StringUtil.substitute() which provides ordered
substitution using the same {0} and {1} style tokens, but doesn't have any
formatting.
Sam
---
We're Hiri
Neat, though it breaks backward compatibility -- each regexp is
converted to string before the comparison, IIRC. (Compatibility may
not be a big problem in practice in this case.)
--lars
On 10/16/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> allow RegEx in case
>
> var str= 'a';
> switc
allow RegEx in case
var str= 'a';
switch( str ) {
case /a/:
alert('a');
break;
case /b/:
alert('b');
break;
}
___
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss
12 matches
Mail list logo