Thank you, Ian.
Most helpful.

> On 16 Apr 2017, at 12:36, Ian Clark <[email protected]> wrote:
> 
> Raul is right: there's no native concept of a "dictionary" in J.
> 
> But dictionaries, as you see them used in Python & Swift, are alive and
> well in J. They are employed by the J system itself for just the same
> purposes as Apple does. (Xcode users: I'm referring to NSDictionary and
> Property Lists (.plist)).
> 
> Here's 2 examples to play with, which should work with any J version, any
> user session and in any locale:
> 
>   ds=: SystemFolders_j_
>   du=: UserFolders_j_
>   $ds
> 12 2
> 
> But you ask what's the *recommended* way to implement a dictionary?
> 
> Python's motto is declared to be "there's only one way to do it." J's motto
> ought to be "there's always one more way to do it". In this case we
> implement a dictionary as a 2-column boxed array. If the J system uses it,
> that's a recommendation.
> 
> Do: "inserting, removing, fetching and editing" as you do with any list.
> (NB: ds is a 2-D array, or "table", i.e. is a list of lists.)
> 
> You can catenate two dictionaries like this:
>   dc=: ds,du
> 
> You can remove the 6th and 7th entries of ds like this:
>   (5 {. ds) , (7 }. ds)
> or, more professionally, like this:
>   1 1 1 1 1 0 0 1 1 1 1 1 # ds
> 
> You can insert a new item like this:
>   ds , 'apps' ; '/applications'
> 
> Here's a verb to lookup a string (y) within a dictionary (x):
>   lookup=: 4 : '>1{ x {~ ({."1 x) i. <y'
>   ds lookup 'user'
> /users/ianclark/j64-805-user
>   ds lookup 'addons'
> /applications/j64-805/addons
> 
> 
> On Wed, Apr 12, 2017 at 1:34 PM, Herbert Weissenbaeck // Privat <
> [email protected]> wrote:
> 
>> Next beginner's question: What would be an efficient/fast (or the
>> recommended) J way to implement a dictionary with strings as keys and
>> arbitrary contents (nouns, verbs, boxes) as values, which allows inserting,
>> removing, fetching and editing?
>> 
>> Thank you.
>> 
>> 
>> 
>> 
>> Sent from my iPhone
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to