For Programmers: Free Programming Magazines  


Home > Archive > Cobol > March 2006 > Re: Java compatibility issues (WAS: MF having issues?)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Java compatibility issues (WAS: MF having issues?)
Frank Swarbrick

2006-03-09, 6:55 pm

Anyone for "associate arrays"?

In the language D you can do the following:

int[char[]] b; // associative array b of ints that are
// indexed by an array of characters.
// The KeyType is char[]
b["hello"] = 3; // set value associated with key "hello" to 3
func(b["hello"]); // pass 3 as parameter to func()

This is from http://www.digitalmars.com/d/arrays.html#associative if you're
interested. What I like about it is it's directly supported by the
language.

So for Oliver's example, I'd imagine something like:

class Pair {
DisplayableObject displayable;
TextForMethodName text;
}

Pair[char[]] p;
p["key"] = new Pair();
p["key"].displayable = myDisplayableObject;
p["key"].text = "Object Label";

print(p["anotherKey"].text);

or possibly:

Pair[char[]] pairs;
Pair p = new Pair();
p.displayable = myDisplayableObject;
p.text = "Object Label";
pairs["key"] = p;

print(pairs["anotherKey"].text);

Don't have the D compiler at work, so I can't check it, but it looks about
right...

Frank


---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
Michael Wojcik

2006-03-10, 6:55 pm


In article <47bavkFemhcfU1@individual.net>, "Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> writes:
> Anyone for "associate arrays"?


*Associative* arrays, I think. "Associate arrays" would be arrays
that are looking forward to another promotion. :-)

> In the language D you can do the following:
>
> int[char[]] b; // associative array b of ints that are
> // indexed by an array of characters.
> // The KeyType is char[]
> b["hello"] = 3; // set value associated with key "hello" to 3
> func(b["hello"]); // pass 3 as parameter to func()


Yes, D has a bunch of nice features.

Associative arrays are typically found in scripting languages like
Awk and Perl, but they're also found in some general-purpose
languages. They're usually really just hash tables with array-like
syntax, though other implementations are possible.

To tie this back to another subtopic, associative arrays can be used
to implement decision tables - so they can be a replacement for COBOL
EVALUATE. The most general approach is to create an associative
array of functions or (for non-functional languages) function
references.

--
Michael Wojcik michael.wojcik@microfocus.com

Pocket #9: A complete "artificial glen" with rocks, and artificial moon,
and forester's station. Excellent for achieving the effect of the
sublime without going out-of-doors. -- Joe Green
Frank Swarbrick

2006-03-13, 6:55 pm

Michael Wojcik<mwojcik@newsguy.com> 03/10/06 11:32 AM >>>
>
>In article <47bavkFemhcfU1@individual.net>, "Frank Swarbrick"

<Frank.Swarbrick@efirstbank.com> writes:
>
>*Associative* arrays, I think. "Associate arrays" would be arrays
>that are looking forward to another promotion. :-)
>
>
>Yes, D has a bunch of nice features.
>
>Associative arrays are typically found in scripting languages like
>Awk and Perl, but they're also found in some general-purpose
>languages. They're usually really just hash tables with array-like
>syntax, though other implementations are possible.


Yeah, I guess it's what might be termed "syntactic sugar", but I'm all for
that, personally. It makes things much more readable, even if internally
it's doing the same thing as function or method calls.

>To tie this back to another subtopic, associative arrays can be used
>to implement decision tables - so they can be a replacement for COBOL
>EVALUATE. The most general approach is to create an associative
>array of functions or (for non-functional languages) function
>references.


That's certainly an interesting idea.

Frank


---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com