Re: Support for operator overloading

Joao Victor <[email protected]> Tue, 29 Nov 2005 11:58:39 +0000
Newsgroups gmane.comp.java.beanshell.devel
Message-ID <[email protected]>
I didn't mean to start a holy/flame war about the subject.

You could think "then use groovy", but Groovy doesn't work for me
because its runtime is too big. And i personally think operator
overloading is a very nice add-on scripts can give to the Java
language.

*Anyway*, i just asked it in the list because i didn't want to
reinvent the wheel. Since nobody said "i did it before", i started
doing it myself. I've already got some operators working.

Cheers,
J.V.



2005/11/28, Yemi D. Bedu <yemi-DnQzskBZRmpWk0Htik3J/[email protected]>:
> Hello,
> I thought of a third syntax format:
> Alias.map("#1 + #2", "MyArray.combine(#1, #2)");
> Alias.map("% #1 #2 #3",
> "StringBuffer.append(#1).append(#2).append(#3)");
> Alias.map("#1[#2]", "#1.getValue(#2)");
> Alias.map("#1[#2]= #3", "#1.setValue(#2, #3)")
>
> We can then use the Alias as a scope executor:
> Alias.setRemoteSyntax("t = newArray(); a = t['s']; t['b'] = 'c';");
> Alias.getRemoteSyntax(); // -> "t = newArray(); a = t['s']; t['b'] =
> 'c';"
> Alias.getLocalSyntax(); // -> "t = newArray(); a = t.getValue('s');
> t.setValue('b', 'c');"
> Alias.execute();
>
> If Beanshell had an initial alias, you can then use all this:
> currentAlias = This.getAlias();
> currentAlias.map("#1 + #2", "(#1 instanceof myArray && #2 instanceof
> myArray)? #1.add(#2) : #1 + #2");
> There is the infinite loop call issue, but that might be solvable by
> allowing the choice of aliasing to drop off on first fails. This would
> mean that if you have a succesfull translation, it would loop to the
> same line, but a fail would go to any of the remaining matching aliases.
> Then you can chain the alais.
>
> Or for this:
> currentAlias.map("#1 + #2", "#1.add(#2)", "#1 instanceof myArray && #2
> instanceof myArray");
>
> It would a conditional alias. The shorter form would mean map(from, to,
> true); though a little dangerous. Good day.
>
> Yemi Bedu
>
> P&R Fasteners
> 325 Pierce St
> Somerset, NJ 08873
> 732-302-3600
>
> -----Original Message-----
> From: beanshell-developers-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> [mailto:beanshell-developers-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] On Behalf Of
> Joao Victor
> Sent: Sunday, November 27, 2005 11:12 AM
> To: beanshell-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Subject: [Beanshell-dev] Support for operator overloading
>
> Hi all,
>
> Does anybody know if there has been any work, or plan, to make Beanshell
> support operator overloading?
>
> Because i was thinking about adding that support (would be very useful
> for this project i'm working on), but i don't want to reinvent the
> wheel.
>
> Cheers,
> J.V.
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files for problems?  Stop!  Download the new AJAX search engine that
> makes searching your log files as easy as surfing the  web.  DOWNLOAD
> SPLUNK!
> http://ads.osdn.com/?ad_idv37&alloc_id865&op=ick
> _______________________________________________
> Beanshell-developers mailing list
> Beanshell-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-developers
>
>


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click