[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

`not' in parameter lists

Daniel Brockman

7/16/2005 6:14:00 PM

13 Answers

Mark Hubbart

7/16/2005 6:47:00 PM

0

On 7/16/05, Daniel Brockman <daniel@brockman.se> wrote:
> I just noticed that all of the following give syntax errors:
>
> * assert not foo
>
> * assert not(foo)
>
> * assert(not foo)
>
> * assert(not(foo))
>
> I would like them all to be equivalent to the following:
>
> assert !foo
>
> At the _very_ least, the fully-bracketed one should work,
> but it would be great if they all worked.

First, remember that 'not' is a keyword, not a method. So it won't
work as a method call.

However, it's true that you can't use it directly in parameter lists.
You can get around it like this:
assert((not foo))
The extra parens make the 'not foo' evaluate separately from the
parameter list, and it works.

cheers,
Mark


Devin Mullins

7/16/2005 7:13:00 PM

0

Mark Hubbart wrote:

>However, it's true that you can't use it directly in parameter lists.
>You can get around it like this:
> assert((not foo))
>The extra parens make the 'not foo' evaluate separately from the
>parameter list, and it works.
>
>
Also, oddly,
assert (not foo)

Devin



Daniel Brockman

7/16/2005 8:01:00 PM

0

Devin Mullins

7/16/2005 9:27:00 PM

0

Daniel Brockman wrote:

>I realize that ‘not foo not bar and not baz’ would be confusing.
>But I maintain that there is only one way to parse ‘assert not foo?’,
>and that it looks better than ‘assert !foo?’.
>
>
Well, I agree with you. There's only one way to parse `assert puts foo`
that I know of, too. Also, I like the ability to do a LISP-with-commas
syntax, though Ruby disallows it sometimes. But whatever.

Devin



Daniel Brockman

7/17/2005 1:56:00 AM

0

Devin Mullins

7/17/2005 2:41:00 AM

0

Daniel Brockman wrote:

>>Also, I like the ability to do a LISP-with-commas syntax,
>>
>>
>Hmm, for a while I thought I had invented that. :-)
>
>
>>though Ruby disallows it sometimes.
>>
>>
>When does Ruby disallow it?
>
>
OK, maybe I'm crazy. I thought I had seen Ruby complain about it once,
but I can't get it to happen now. Nevermind!

Devin



Mark Hubbart

7/17/2005 7:24:00 AM

0

On 7/16/05, Daniel Brockman <daniel@brockman.se> wrote:
> Devin Mullins <twifkak@comcast.net> writes:
>
> > Mark Hubbart wrote:
> >
> >> However, it's true that you can't use it directly in parameter lists.
> >> You can get around it like this:
> >> assert((not foo))
> >> The extra parens make the 'not foo' evaluate separately from the
> >> parameter list, and it works.
> >
> > Also, oddly,
> > assert (not foo)
>
> Yes, I know 'not' is a keyword and I know you can work around the
> problem like that. That doesn't mean the current behavior of raising
> a syntax error when seeing not in a parameter list is useful.

I agree... I prefer using the english "not, "and", and "or" boolean
operators in almost every case. There was a thread on this exact
subject a while back, though I can't find it at the moment, which
focused more on the use of "or" and "and". There wasn't a resolution
to it that I remember, though.

But, 'assert(not(foo))' just looked bizarre to me. If 'foo' were an
expression, and there was a space between 'not' and the first paren,
it wouldn't look so odd, I suppose: 'assert(not (foo or bar))

> The best workaround is to simply use '!', but I prefer the spelled-out
> boolean operators, and I don't see why it should be disallowed here.
>
> I realize that 'not foo not bar and not baz' would be confusing.
> But I maintain that there is only one way to parse 'assert not foo?',
> and that it looks better than 'assert !foo?'.

I wonder if giving a syntax error in these cases was a design
decision, a parser limitation, or just an oversight?

cheers,
Mark


Daniel Brockman

7/17/2005 5:20:00 PM

0

Gary Wright

7/17/2005 5:56:00 PM

0


On Jul 17, 2005, at 1:20 PM, Daniel Brockman wrote:
> Is there any word on the chances of this becoming allowed in the
> future?
> I mean, is it definitely ruled out, or is there room for persuation?

Personally I don't like this sort of "change" to a language or library.
There are certain *core* ideas in a programming language (or library
or framework) that should be obvious to every single programmer using
that system. Flexibility in a language is important but should only
be used to augment the core language. When the flexibility is used
to obfuscate the core ideas via a "dialect" the result is often only
of use to the original author.

Here is a function from the Version 7 Bourne Shell that was
notorious for its abuse of C macros:

INT pathopen(path, name)
REG STRING path, name;
{
REG UFD f;

REP path=catpath(path,name);
PER (f=open(curstak(), O_RDONLY))<0 ANDF path DONE
return(f);
}

What exactly is going on here? What is REP, PER, ANDF, DONE?


Gary Wright



Daniel Brockman

7/17/2005 6:34:00 PM

0