Using arrays with pseudo "bsh" classes

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using arrays with pseudo "bsh" classes

Gerry Duprey
Howdy,

I've gotten into using the ability for methods in beanshell to return "this"
as a lasting reference to the method for creating "objects" in my scripts.

However, I'm finding I can't (or more likely, don't know how) to create
arrays of those references.

For example, consider this bit of a script:

Employee(eName, eId) {
   name = eName;
   id = eId;
   return this;
}

fred = Employee("Fred Fredrickson", "0000001");
tom = Employee("Tom Thomson", "00000002");
harry = Employee("Harry Harrison", "0000003");

print(tom.name);
print(harry.id);

---

What I'd like to do is create an array of "Employee" like

Employee [] empList = new Employee[10];

But I get an error saying there is no class Employee.  I tried to declare
the array more generically, but there doesn't seem to be a way to declare an
array without at least one mention of it's type (which I do understand).

So, my question is -- is there a way to create arrays of references to
methods?  If so, could someone give me an example of the syntax?

Thanks!

Gerry

--
Gerry Duprey
Ann Arbor, MI 48103
http://www.cdp1802.org


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Using arrays with pseudo "bsh" classes

Daniel Wunsch
On Sunday 31 July 2005 02:46, Gerry Duprey wrote:

> So, my question is -- is there a way to create arrays of references to
> methods?  If so, could someone give me an example of the syntax?

eris:~/tmp > bsh
BeanShell 2.0b4 - by Pat Niemeyer ([hidden email])
bsh % Foo() { return this; }
bsh % var fooArray = new Object[10];
bsh % for (int i=0; i<10; i++) {
fooArray[i] = Foo();
}
bsh % print(fooArray[0]);
'this' reference (XThis) to Bsh object: NameSpace: Foo (bsh.NameSpace@4b4333)
(method)
bsh %



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Using arrays with pseudo "bsh" classes

Daniel Wunsch
i thought a bit more about this:

i like to use typed arguments for methods in beanshell,
because in most cases i need to remember the correct
type anyway. sometimes i wish i could use that for
beanshell  closures, too.

atm i use something like this
    var/*Foo*/ anArgument

of couse this doesn't get me the main advantage of
declaring typed parameters, namely the error messages
when i try to pass in a value with the wrong type.

it would be quite nice, if code like this worked:

Foo() { return this; }
void bar(Foo argument) { ... }

daniel


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Using arrays with pseudo "bsh" classes

Pankaj Kumar
In reply to this post by Gerry Duprey
Try something like this:

empList = new Object[] { Employee("Fred Fredrickson", "0000001"),
  Employee("Tom Thomson", "00000002"),
  Employee("Harry Harrison", "0000003") };

for (emp:empList){ print(emp.name); }

/Pankaj


On 7/30/05, Gerry Duprey <[hidden email]> wrote:

> Howdy,
>
> I've gotten into using the ability for methods in beanshell to return "this"
> as a lasting reference to the method for creating "objects" in my scripts.
>
> However, I'm finding I can't (or more likely, don't know how) to create
> arrays of those references.
>
> For example, consider this bit of a script:
>
> Employee(eName, eId) {
>   name = eName;
>   id = eId;
>   return this;
> }
>
> fred = Employee("Fred Fredrickson", "0000001");
> tom = Employee("Tom Thomson", "00000002");
> harry = Employee("Harry Harrison", "0000003");
>
> print(tom.name);
> print(harry.id);
>
> ---
>
> What I'd like to do is create an array of "Employee" like
>
> Employee [] empList = new Employee[10];
>
> But I get an error saying there is no class Employee.  I tried to declare
> the array more generically, but there doesn't seem to be a way to declare an
> array without at least one mention of it's type (which I do understand).
>
> So, my question is -- is there a way to create arrays of references to
> methods?  If so, could someone give me an example of the syntax?
>
> Thanks!
>
> Gerry
>
> --
> Gerry Duprey
> Ann Arbor, MI 48103
> http://www.cdp1802.org
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Using arrays with pseudo "bsh" classes

Alexey Zinger
In reply to this post by Gerry Duprey
You'll need to create an array of Method objects together with the objects
you'll be calling them on.  Check out java.lang.reflect package.

--- Gerry Duprey <[hidden email]> wrote:

> Howdy,
>
> I've gotten into using the ability for methods in beanshell to return "this"
> as a lasting reference to the method for creating "objects" in my scripts.
>
> However, I'm finding I can't (or more likely, don't know how) to create
> arrays of those references.
>
> For example, consider this bit of a script:
>
> Employee(eName, eId) {
>    name = eName;
>    id = eId;
>    return this;
> }
>
> fred = Employee("Fred Fredrickson", "0000001");
> tom = Employee("Tom Thomson", "00000002");
> harry = Employee("Harry Harrison", "0000003");
>
> print(tom.name);
> print(harry.id);
>
> ---
>
> What I'd like to do is create an array of "Employee" like
>
> Employee [] empList = new Employee[10];
>
> But I get an error saying there is no class Employee.  I tried to declare
> the array more generically, but there doesn't seem to be a way to declare an
> array without at least one mention of it's type (which I do understand).
>
> So, my question is -- is there a way to create arrays of references to
> methods?  If so, could someone give me an example of the syntax?
>
> Thanks!
>
> Gerry
>
> --
> Gerry Duprey
> Ann Arbor, MI 48103
> http://www.cdp1802.org
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Using arrays with pseudo "bsh" classes

Alexey Zinger
Sorry about this, had a brain freeze moment and thought you wanted an array of
compiled methods for some reason.

--- Alexey Zinger <[hidden email]> wrote:

> You'll need to create an array of Method objects together with the objects
> you'll be calling them on.  Check out java.lang.reflect package.
>
> --- Gerry Duprey <[hidden email]> wrote:
>
> > Howdy,
> >
> > I've gotten into using the ability for methods in beanshell to return
> "this"
> > as a lasting reference to the method for creating "objects" in my scripts.
> >
> > However, I'm finding I can't (or more likely, don't know how) to create
> > arrays of those references.
> >
> > For example, consider this bit of a script:
> >
> > Employee(eName, eId) {
> >    name = eName;
> >    id = eId;
> >    return this;
> > }
> >
> > fred = Employee("Fred Fredrickson", "0000001");
> > tom = Employee("Tom Thomson", "00000002");
> > harry = Employee("Harry Harrison", "0000003");
> >
> > print(tom.name);
> > print(harry.id);
> >
> > ---
> >
> > What I'd like to do is create an array of "Employee" like
> >
> > Employee [] empList = new Employee[10];
> >
> > But I get an error saying there is no class Employee.  I tried to declare
> > the array more generically, but there doesn't seem to be a way to declare
> an
> > array without at least one mention of it's type (which I do understand).
> >
> > So, my question is -- is there a way to create arrays of references to
> > methods?  If so, could someone give me an example of the syntax?
> >
> > Thanks!
> >
> > Gerry
> >
> > --
> > Gerry Duprey
> > Ann Arbor, MI 48103
> > http://www.cdp1802.org
> >
> >
> > -------------------------------------------------------
> > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> > from IBM. Find simple to follow Roadmaps, straightforward articles,
> > informative Webcasts and more! Get everything you need to get up to
> > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> > _______________________________________________
> > Beanshell-users mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/beanshell-users
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com 
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>



               
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs 
 


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users