use of + and - in DSL?

View: New views
20 Messages — Rating Filter:   Alert me  

use of + and - in DSL?

by Maurice Nicholson old :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm writing a Groovy builder for Compass queries. (Compass is a search
engine framework built on top of Lucene.)

It would be nice to use + and - in the builder syntax since it reflects
the Lucene string query format, eg:

    def query = builder.build {
        +term('keywords', 'book')
        -term('keywords', 'audio')
        queryString('color theory')
    }

would build a query that in Lucene query string syntax looks like:

    +keywords:book -term:audio all:color all:theory

However... from a very quick cursory test with an example like the
above, I found the "-" calls InvokerHelper.negate() on the object
returned by term(...) but the negate() method only handles specific classes.

Is what I'm trying to do possible?

Thanks,
Maurice


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Jochen Theodorou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Maurice Nicholson schrieb:

> Hi,
>
> I'm writing a Groovy builder for Compass queries. (Compass is a search
> engine framework built on top of Lucene.)
>
> It would be nice to use + and - in the builder syntax since it reflects
> the Lucene string query format, eg:
>
>    def query = builder.build {
>        +term('keywords', 'book')
>        -term('keywords', 'audio')
>        queryString('color theory')
>    }
>
> would build a query that in Lucene query string syntax looks like:
>
>    +keywords:book -term:audio all:color all:theory
>
> However... from a very quick cursory test with an example like the
> above, I found the "-" calls InvokerHelper.negate() on the object
> returned by term(...) but the negate() method only handles specific
> classes.
>
> Is what I'm trying to do possible?

+ and - or not methods you can influence... you could do

     def query = builder.build {
         '+term' ('keywords', 'book')
         '-term' ('keywords', 'audio')
         queryString('color theory')
     }

but that looks a bit strange.

bye blackdrag

--
Jochen "blackdrag" Theodorou
Groovy Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Maurice Nicholson old :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, and thanks for suggestion, but I agree it does look strange.

And what I have working now (with text method names instead of +/-) is good enough.

But... are there any plans to open up this functionality? I'm just curious.

Jochen Theodorou wrote:
Maurice Nicholson schrieb:
> Hi,
>
> I'm writing a Groovy builder for Compass queries. (Compass is a search
> engine framework built on top of Lucene.)
>
> It would be nice to use + and - in the builder syntax since it reflects
> the Lucene string query format, eg:
>
>    def query = builder.build {
>        +term('keywords', 'book')
>        -term('keywords', 'audio')
>        queryString('color theory')
>    }
>
> would build a query that in Lucene query string syntax looks like:
>
>    +keywords:book -term:audio all:color all:theory
>
> However... from a very quick cursory test with an example like the
> above, I found the "-" calls InvokerHelper.negate() on the object
> returned by term(...) but the negate() method only handles specific
> classes.
>
> Is what I'm trying to do possible?

+ and - or not methods you can influence... you could do

     def query = builder.build {
         '+term' ('keywords', 'book')
         '-term' ('keywords', 'audio')
         queryString('color theory')
     }

but that looks a bit strange.

bye blackdrag

--
Jochen "blackdrag" Theodorou
Groovy Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Re: use of + and - in DSL?

by Alexandru Popescu ☀ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 4/22/07, Maurice Nicholson <maurice.nicholson@...> wrote:
>
> Ok, and thanks for suggestion, but I agree it does look strange.
>
> And what I have working now (with text method names instead of +/-) is good
> enough.
>
> But... are there any plans to open up this functionality? I'm just curious.
>

I think it may be possible to "open" these ops as method calls,
somehow in the same way getAt() and synonyms are working.  But I am
not sure when this will be possible :-).

./alex
--
.w( the_mindstorm )p.
_____________________________________
  Alexandru Popescu, OSS Evangelist
TestNG/Groovy/AspectJ/WebWork/more...
  Information Queue ~ www.InfoQ.com



>
> Jochen Theodorou wrote:
> >
> > Maurice Nicholson schrieb:
> >> Hi,
> >>
> >> I'm writing a Groovy builder for Compass queries. (Compass is a search
> >> engine framework built on top of Lucene.)
> >>
> >> It would be nice to use + and - in the builder syntax since it reflects
> >> the Lucene string query format, eg:
> >>
> >>    def query = builder.build {
> >>        +term('keywords', 'book')
> >>        -term('keywords', 'audio')
> >>        queryString('color theory')
> >>    }
> >>
> >> would build a query that in Lucene query string syntax looks like:
> >>
> >>    +keywords:book -term:audio all:color all:theory
> >>
> >> However... from a very quick cursory test with an example like the
> >> above, I found the "-" calls InvokerHelper.negate() on the object
> >> returned by term(...) but the negate() method only handles specific
> >> classes.
> >>
> >> Is what I'm trying to do possible?
> >
> > + and - or not methods you can influence... you could do
> >
> >      def query = builder.build {
> >          '+term' ('keywords', 'book')
> >          '-term' ('keywords', 'audio')
> >          queryString('color theory')
> >      }
> >
> > but that looks a bit strange.
> >
> > bye blackdrag
> >
> > --
> > Jochen "blackdrag" Theodorou
> > Groovy Tech Lead (http://groovy.codehaus.org)
> > http://blackdragsview.blogspot.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/use-of-%2B-and---in-DSL--tf3623677.html#a10128406
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by glaforge :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 4/23/07, Alexandru Popescu ☀ <the.mindstorm.mailinglist@...> wrote:
> [...]
> I think it may be possible to "open" these ops as method calls,
> somehow in the same way getAt() and synonyms are working.  But I am
> not sure when this will be possible :-).

Not all operators are open to overloading.
+ and - unary operators aren't currently open.
There's minus() for a - b and plus() for a + b, and there's the
unfortunately named negate() method for ~.
I think we can open the discussion of operators to open to
overloading, and see whether we can find a good name for methods for +
and - (plus and minus being taken, as well as negate)... positive() ?
negative() ?
And do we want to open + and - and potentially other operators?

--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

Re: use of + and - in DSL?

by Charles Oliver Nutter-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Guillaume Laforge wrote:

> On 4/23/07, Alexandru Popescu ☀ <the.mindstorm.mailinglist@...>
> wrote:
>> [...]
>> I think it may be possible to "open" these ops as method calls,
>> somehow in the same way getAt() and synonyms are working.  But I am
>> not sure when this will be possible :-).
>
> Not all operators are open to overloading.
> + and - unary operators aren't currently open.
> There's minus() for a - b and plus() for a + b, and there's the
> unfortunately named negate() method for ~.
> I think we can open the discussion of operators to open to
> overloading, and see whether we can find a good name for methods for +
> and - (plus and minus being taken, as well as negate)... positive() ?
> negative() ?
> And do we want to open + and - and potentially other operators?

Ruby allows defining at least unary + and - as the +@ and -@ methods, so
maybe some similar naming convention would work for Groovy. I don't
believe Ruby allows defining any other unary operations.

Or if you really want specific names, I suppose "negate" works for unary
minus...dunno about unary plus.

Or maybe "unaryMinus" and "unaryPlus"?

Also, "positive" and "negative" are adjectives, where unary minus
usually modifies the value in question (and I guess unary plus generally
doesn't do anything, but it could).

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Alexandru Popescu ☀ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 4/23/07, Charles Oliver Nutter <charles.nutter@...> wrote:

> Guillaume Laforge wrote:
> > On 4/23/07, Alexandru Popescu ☀ <the.mindstorm.mailinglist@...>
> > wrote:
> >> [...]
> >> I think it may be possible to "open" these ops as method calls,
> >> somehow in the same way getAt() and synonyms are working.  But I am
> >> not sure when this will be possible :-).
> >
> > Not all operators are open to overloading.
> > + and - unary operators aren't currently open.
> > There's minus() for a - b and plus() for a + b, and there's the
> > unfortunately named negate() method for ~.
> > I think we can open the discussion of operators to open to
> > overloading, and see whether we can find a good name for methods for +
> > and - (plus and minus being taken, as well as negate)... positive() ?
> > negative() ?
> > And do we want to open + and - and potentially other operators?
>
> Ruby allows defining at least unary + and - as the +@ and -@ methods, so
> maybe some similar naming convention would work for Groovy. I don't
> believe Ruby allows defining any other unary operations.
>

As far as I know +@, -@ are not valid Java identifiers, so this would
not work. I would rather go for clear names as unaryPlus, unaryMinus.

./alex
--
.w( the_mindstorm )p.
_____________________________________
  Alexandru Popescu, OSS Evangelist
TestNG/Groovy/AspectJ/WebWork/more...
  Information Queue ~ www.InfoQ.com


> Or if you really want specific names, I suppose "negate" works for unary
> minus...dunno about unary plus.
>
> Or maybe "unaryMinus" and "unaryPlus"?
>
> Also, "positive" and "negative" are adjectives, where unary minus
> usually modifies the value in question (and I guess unary plus generally
> doesn't do anything, but it could).
>
> - Charlie
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

Re: use of + and - in DSL?

by Joel Neely :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This Groovy newbie likes "positive" and "negative",
as they follow POLS (at least for American ears ;-)

"1 + 1" -> "one plus one"
"2 - 1" -> "two minus one"
"+1"    -> "positive one"
"-1"    -> "negative one"

-jn-

On 4/23/07, Guillaume Laforge <glaforge@...> wrote:
> I think we can open the discussion of operators to open to
> overloading, and see whether we can find a good name for methods for +
> and - (plus and minus being taken, as well as negate)... positive() ?
> negative() ?

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Maurice Nicholson old :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Alexandru Popescu ☀ wrote:

> On 4/23/07, Charles Oliver Nutter <charles.nutter@...> wrote:
>> Guillaume Laforge wrote:
>> > On 4/23/07, Alexandru Popescu ☀ <the.mindstorm.mailinglist@...>
>> > wrote:
>> >> [...]
>> >> I think it may be possible to "open" these ops as method calls,
>> >> somehow in the same way getAt() and synonyms are working.  But I am
>> >> not sure when this will be possible :-).
>> >
>> > Not all operators are open to overloading.
>> > + and - unary operators aren't currently open.
>> > There's minus() for a - b and plus() for a + b, and there's the
>> > unfortunately named negate() method for ~.
>> > I think we can open the discussion of operators to open to
>> > overloading, and see whether we can find a good name for methods for +
>> > and - (plus and minus being taken, as well as negate)... positive() ?
>> > negative() ?
>> > And do we want to open + and - and potentially other operators?
>>
>> Ruby allows defining at least unary + and - as the +@ and -@ methods, so
>> maybe some similar naming convention would work for Groovy. I don't
>> believe Ruby allows defining any other unary operations.
>>
>
> As far as I know +@, -@ are not valid Java identifiers, so this would
> not work. I would rather go for clear names as unaryPlus, unaryMinus.
>
Yeah AFAICT the Groovy way is to translate operators to English named
methods in th GDK, so either uninaryPlus/uninaryMinus or
positive/negative sit fine with me.

Should I raise an issue to track this?

> ./alex
> --
> .w( the_mindstorm )p.
> _____________________________________
>  Alexandru Popescu, OSS Evangelist
> TestNG/Groovy/AspectJ/WebWork/more...
>  Information Queue ~ www.InfoQ.com
>
>
>> Or if you really want specific names, I suppose "negate" works for unary
>> minus...dunno about unary plus.
>>
>> Or maybe "unaryMinus" and "unaryPlus"?
>>
>> Also, "positive" and "negative" are adjectives, where unary minus
>> usually modifies the value in question (and I guess unary plus generally
>> doesn't do anything, but it could).
>>
>> - Charlie
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by glaforge :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Agreed :-)

On 4/23/07, Joel Neely <joel.neely@...> wrote:

> This Groovy newbie likes "positive" and "negative",
> as they follow POLS (at least for American ears ;-)
>
> "1 + 1" -> "one plus one"
> "2 - 1" -> "two minus one"
> "+1"    -> "positive one"
> "-1"    -> "negative one"
>
> -jn-
>
> On 4/23/07, Guillaume Laforge <glaforge@...> wrote:
> > I think we can open the discussion of operators to open to
> > overloading, and see whether we can find a good name for methods for +
> > and - (plus and minus being taken, as well as negate)... positive() ?
> > negative() ?
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by glaforge :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 4/23/07, Maurice Nicholson <maurice.nicholson@...> wrote:
> [...]
> Yeah AFAICT the Groovy way is to translate operators to English named
> methods in th GDK, so either uninaryPlus/uninaryMinus or
> positive/negative sit fine with me.
>
> Should I raise an issue to track this?

Yes please.

--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Charles Oliver Nutter-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joel Neely wrote:
> This Groovy newbie likes "positive" and "negative",
> as they follow POLS (at least for American ears ;-)
>
> "1 + 1" -> "one plus one"
> "2 - 1" -> "two minus one"
> "+1"    -> "positive one"
> "-1"    -> "negative one"

"+(-1)" -> "negative one", not "positive one", so I would have to
disagree. "positive" doesn't actually force anything positive.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Paul King :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Charles Oliver Nutter wrote:

> Joel Neely wrote:
>> This Groovy newbie likes "positive" and "negative",
>> as they follow POLS (at least for American ears ;-)
>>
>> "1 + 1" -> "one plus one"
>> "2 - 1" -> "two minus one"
>> "+1"    -> "positive one"
>> "-1"    -> "negative one"
>
> "+(-1)" -> "negative one", not "positive one", so I would have to
> disagree. "positive" doesn't actually force anything positive.

But wouldn't you still read the math as positive(negative(1))?
What different objects decide to do semantically is up to them?

Paul.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Joel Neely :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, but it would be a real shock to most ears to hear
"+x" pronounced as "absolute value of x".

I guess that Bob Dylan fans would pronounce "+(-1)" as
"positively minus one"...

Actually I suspect that there's no perfect answer in this case,
as vernacular usage and iron-clad consistency seem to be
at odds. I was erring on the side of obvious vernacular.

(And, being a grammar nazi myself,  must point out that
"unary plus" and "unary minus" are noun phrases... ;-)

-jn-

On 4/23/07, Charles Oliver Nutter <charles.nutter@...> wrote:
> "+(-1)" -> "negative one", not "positive one", so I would have to
> disagree. "positive" doesn't actually force anything positive.
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Maurice Nicholson old :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Guillaume Laforge wrote:

> On 4/23/07, Maurice Nicholson <maurice.nicholson@...>
> wrote:
>> [...]
>> Yeah AFAICT the Groovy way is to translate operators to English named
>> methods in th GDK, so either uninaryPlus/uninaryMinus or
>> positive/negative sit fine with me.
>>
>> Should I raise an issue to track this?
>
> Yes please.
>

http://jira.codehaus.org/browse/GROOVY-1851

Thanks :-)

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Maurice Nicholson old :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Charles Oliver Nutter wrote:

> Joel Neely wrote:
>> This Groovy newbie likes "positive" and "negative",
>> as they follow POLS (at least for American ears ;-)
>>
>> "1 + 1" -> "one plus one"
>> "2 - 1" -> "two minus one"
>> "+1"    -> "positive one"
>> "-1"    -> "negative one"
>
> "+(-1)" -> "negative one", not "positive one", so I would have to
> disagree. "positive" doesn't actually force anything positive.
>
> - Charlie
>

True, but we're not just talking about numbers here (I hope).

The default implementation for +number would do nothing but for other
types of object, who knows?

> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by glaforge :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 4/23/07, Maurice Nicholson <maurice.nicholson@...> wrote:
> http://jira.codehaus.org/browse/GROOVY-1851
>
> Thanks :-)

My turn to say thanks ;-)

--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Charles Oliver Nutter-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Maurice Nicholson wrote:

>
>
> Charles Oliver Nutter wrote:
>> Joel Neely wrote:
>>> This Groovy newbie likes "positive" and "negative",
>>> as they follow POLS (at least for American ears ;-)
>>>
>>> "1 + 1" -> "one plus one"
>>> "2 - 1" -> "two minus one"
>>> "+1"    -> "positive one"
>>> "-1"    -> "negative one"
>>
>> "+(-1)" -> "negative one", not "positive one", so I would have to
>> disagree. "positive" doesn't actually force anything positive.
>>
>> - Charlie
>>
>
> True, but we're not just talking about numbers here (I hope).
>
> The default implementation for +number would do nothing but for other
> types of object, who knows?

Well, I guess the rebuttal there is whether "positive" and "negative"
make sense with objects other than numbers :)

At least "unaryPlus" and "unaryMinus" are pretty unambiguous, and
reflect the language grammar directly.

-Charlie (or is that "negative Charlie"?)

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: use of + and - in DSL?

by Marc Stock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

My vote is for unaryPlus/unaryMinus.  Using positive and negative for this would be misleading.  The unary naming prefix makes it very clear what's going on.

-- Marc

On 4/23/07, Charles Oliver Nutter <charles.nutter@...> wrote:
Maurice Nicholson wrote:

>
>
> Charles Oliver Nutter wrote:
>> Joel Neely wrote:
>>> This Groovy newbie likes "positive" and "negative",
>>> as they follow POLS (at least for American ears ;-)
>>>
>>> "1 + 1" -> "one plus one"
>>> "2 - 1" -> "two minus one"
>>> "+1"    -> "positive one"
>>> "-1"    -> "negative one"
>>
>> "+(-1)" -> "negative one", not "positive one", so I would have to
>> disagree. "positive" doesn't actually force anything positive.
>>
>> - Charlie
>>
>
> True, but we're not just talking about numbers here (I hope).
>
> The default implementation for +number would do nothing but for other
> types of object, who knows?

Well, I guess the rebuttal there is whether "positive" and "negative"
make sense with objects other than numbers :)

At least "unaryPlus" and "unaryMinus" are pretty unambiguous, and
reflect the language grammar directly.

-Charlie (or is that "negative Charlie"?)

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email



Re: use of + and - in DSL?

by Emmanuel Bernard-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

for the original use case (Lucene),
+ means explicit inclusion
- means explicit exclusion

+(-word) does not make sense

For an Entity, not having the compact syntax will end up multiply the  
groovy file LoC by 3 at least

On 23 avr. 07, at 08:34, Charles Oliver Nutter wrote:

> Maurice Nicholson wrote:
>> Charles Oliver Nutter wrote:
>>> Joel Neely wrote:
>>>> This Groovy newbie likes "positive" and "negative",
>>>> as they follow POLS (at least for American ears ;-)
>>>>
>>>> "1 + 1" -> "one plus one"
>>>> "2 - 1" -> "two minus one"
>>>> "+1"    -> "positive one"
>>>> "-1"    -> "negative one"
>>>
>>> "+(-1)" -> "negative one", not "positive one", so I would have to  
>>> disagree. "positive" doesn't actually force anything positive.
>>>
>>> - Charlie
>>>
>> True, but we're not just talking about numbers here (I hope).
>> The default implementation for +number would do nothing but for  
>> other types of object, who knows?
>
> Well, I guess the rebuttal there is whether "positive" and  
> "negative" make sense with objects other than numbers :)
>
> At least "unaryPlus" and "unaryMinus" are pretty unambiguous, and  
> reflect the language grammar directly.
>
> -Charlie (or is that "negative Charlie"?)
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email