Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #36653 > unrolled thread

Create array using name from string?

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2019-05-28 02:06 -0700
Last post2019-05-29 01:16 -0700
Articles 10 on this page of 30 — 11 participants

Back to article view | Back to comp.lang.javascript


Contents

  Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-28 02:06 -0700
    Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-28 02:11 -0700
    Re: Create array using name from string? "R.Wieser" <address@not.available> - 2019-05-28 11:39 +0200
      Re: Create array using name from string? "R.Wieser" <address@not.available> - 2019-05-28 12:02 +0200
        Re: Create array using name from string? dr.j.r.stockton@gmail.com - 2019-05-28 05:38 -0700
          Re: Create array using name from string? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-05-28 17:06 +0100
            Re: Create array using name from string? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-29 00:22 +0200
              Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-29 00:07 -0700
                Re: Create array using name from string? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-05-29 09:47 +0200
                Re: Create array using name from string? Julio Di Egidio <julio@diegidio.name> - 2019-05-29 10:10 -0700
                  Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-30 11:10 -0700
                  Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-30 11:12 -0700
                    Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-30 11:22 -0700
                      Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-30 11:28 -0700
              Re: Create array using name from string? Julio Di Egidio <julio@diegidio.name> - 2019-05-29 10:24 -0700
                Re: Create array using name from string? Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2019-05-30 11:37 +0200
                  Re: Create array using name from string? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-30 12:35 +0200
                    Re: Create array using name from string? Julio Di Egidio <julio@diegidio.name> - 2019-05-30 03:43 -0700
                    Re: Create array using name from string? Julio Di Egidio <julio@diegidio.name> - 2019-05-30 03:48 -0700
                    Re: Create array using name from string? Gene Wirchenko <genew@telus.net> - 2019-05-30 12:13 -0700
                  Re: Create array using name from string? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-05-30 10:34 -0700
                Re: Create array using name from string? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-05-31 19:01 +0100
                  Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-31 11:21 -0700
                    Re: Create array using name from string? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-06-01 00:31 +0200
                      Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-01 00:40 -0700
                        Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-01 01:10 -0700
                    Re: Create array using name from string? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-06-01 10:14 +0100
          Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-29 00:15 -0700
            Re: Create array using name from string? "R.Wieser" <address@not.available> - 2019-05-29 09:35 +0200
              Re: Create array using name from string? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-29 01:16 -0700

Page 2 of 2 — ← Prev page 1 [2]


#36677

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2019-05-30 10:34 -0700
Message-ID<e04660e5-fb70-40a6-a1cd-68bfa58460fa@googlegroups.com>
In reply to#36670
Cezary Tomczyk wrote:
> On 29/05/2019 19:24, Julio Di Egidio wrote:
> > On Wednesday, 29 May 2019 00:22:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
> > 
> >> (Unfortunately, regarding his code style Dr. Stockton
> >> appears to be stuck the world of Borland Pascal where such distinctions
> >> need not be made because it is not an OOPL in the first place.)
> > 
> > What a nonsensical statement: all the more so since JS is essentially
> > NOT an OO language...
> 
> What is then OO definition?

The generally accepted definition of OOP is described by Benjamin Pierce in TAPL [1][2]. Namely:

  1. Multiple representations: The object dictates what code is
executed, often at runtime using dynamic dispatch
  2. Encapsulation: Hiding of internal representation and providing a
limited interface for access.
  3. Subtyping: Interface sharing
  4. Inheritance: Implementation sharing of shared interfaces.
Generally done through classes or delegation
  5. Open recursion: The ability of a method to refer to other methods
of itself before/after they are defined. (keyword 'this' in JS, 'self'
in Python, 'my' in Perl, etc.)


So JavaScript is "Object-Oriented" because it has a set of features in common with the definition of being Object Oriented.


[1] <https://www.cis.upenn.edu/~bcpierce/tapl/>
[2] See Chapter 18.1 <http://port70.net/~nsz/articles/book/pierce_types_and_programming_languages_2002.pdf> 

[toc] | [prev] | [next] | [standalone]


#36709

FromJohn G Harris <niam@jghnorth.org.uk.invalid>
Date2019-05-31 19:01 +0100
Message-ID<rvq2fepvtr303ehaofhnfq20ub59go0q97@4ax.com>
In reply to#36669
On Wed, 29 May 2019 10:24:17 -0700 (PDT), Julio Di Egidio
<julio@diegidio.name> wrote:

>On Wednesday, 29 May 2019 00:22:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
>
>> (Unfortunately, regarding his code style Dr. Stockton 
>> appears to be stuck the world of Borland Pascal where such distinctions
>> need not be made because it is not an OOPL in the first place.)
>
>What a nonsensical statement: all the more so since JS is essentially
>NOT an OO language...

If you believe that
  a Functional language cannot be an OO language and cannot be a
    procedural language,
  an OO language cannot be a procedural language and cannot be a 
    Functional language,
  a procedural language cannot be a Functional language and cannot
    be an OO language,

then you have to say it's one of these and furiously deny that it's
either of the other two.

  John

[toc] | [prev] | [next] | [standalone]


#36710

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2019-05-31 11:21 -0700
Message-ID<37d49264-5062-4412-9486-d25d9a13560c@googlegroups.com>
In reply to#36709
Den fredag 31 maj 2019 kl. 20:01:41 UTC+2 skrev John G Harris:
> On Wed, 29 May 2019 10:24:17 -0700 (PDT), Julio Di Egidio
> <julio@diegidio.name> wrote:
> 
> >On Wednesday, 29 May 2019 00:22:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
> >
> >> (Unfortunately, regarding his code style Dr. Stockton 
> >> appears to be stuck the world of Borland Pascal where such distinctions
> >> need not be made because it is not an OOPL in the first place.)
> >
> >What a nonsensical statement: all the more so since JS is essentially
> >NOT an OO language...
> 
> If you believe that
>   a Functional language cannot be an OO language and cannot be a
>     procedural language,
>   an OO language cannot be a procedural language and cannot be a 
>     Functional language,
>   a procedural language cannot be a Functional language and cannot
>     be an OO language,
> 
> then you have to say it's one of these and furiously deny that it's
> either of the other two.
> 
>   John

Well i would say i have a procedural programming style in Javascript, sometimes i invoke functions most for stringhandling, and occasionally i use objects mostly to confuse myself....

[toc] | [prev] | [next] | [standalone]


#36712

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2019-06-01 00:31 +0200
Message-ID<XnsAA6155475950eejj99@194.109.6.166>
In reply to#36710
=?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 31
May 2019 in comp.lang.javascript: 

> Den fredag 31 maj 2019 kl. 20:01:41 UTC+2 skrev John G Harris:
>> On Wed, 29 May 2019 10:24:17 -0700 (PDT), Julio Di Egidio
>> <julio@diegidio.name> wrote:
>> 
>> >On Wednesday, 29 May 2019 00:22:33 UTC+2, Thomas 'PointedEars' Lahn 
>> >wrote: 
>> >
>> >> (Unfortunately, regarding his code style Dr. Stockton 
>> >> appears to be stuck the world of Borland Pascal where such
>> >> distinctions need not be made because it is not an OOPL in the first
>> >> place.) 
>> >
>> >What a nonsensical statement: all the more so since JS is essentially
>> >NOT an OO language...
>> 
>> If you believe that
>>   a Functional language cannot be an OO language and cannot be a
>>     procedural language,
>>   an OO language cannot be a procedural language and cannot be a 
>>     Functional language,
>>   a procedural language cannot be a Functional language and cannot
>>     be an OO language,
>> 
>> then you have to say it's one of these and furiously deny that it's
>> either of the other two.
>> 
>>   John
> 
> Well i would say i have a procedural programming style in Javascript,
> sometimes i invoke functions most for stringhandling, and occasionally i
> use objects mostly to confuse myself.... 

I agree.



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#36715

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2019-06-01 00:40 -0700
Message-ID<ebc04b36-4271-424c-91e0-a9cc9bfa0dbc@googlegroups.com>
In reply to#36712
Den lördag 1 juni 2019 kl. 00:31:32 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 31
> May 2019 in comp.lang.javascript: 
> 
> > Den fredag 31 maj 2019 kl. 20:01:41 UTC+2 skrev John G Harris:
> >> On Wed, 29 May 2019 10:24:17 -0700 (PDT), Julio Di Egidio
> >> <julio@diegidio.name> wrote:
> >> 
> >> >On Wednesday, 29 May 2019 00:22:33 UTC+2, Thomas 'PointedEars' Lahn 
> >> >wrote: 
> >> >
> >> >> (Unfortunately, regarding his code style Dr. Stockton 
> >> >> appears to be stuck the world of Borland Pascal where such
> >> >> distinctions need not be made because it is not an OOPL in the first
> >> >> place.) 
> >> >
> >> >What a nonsensical statement: all the more so since JS is essentially
> >> >NOT an OO language...
> >> 
> >> If you believe that
> >>   a Functional language cannot be an OO language and cannot be a
> >>     procedural language,
> >>   an OO language cannot be a procedural language and cannot be a 
> >>     Functional language,
> >>   a procedural language cannot be a Functional language and cannot
> >>     be an OO language,
> >> 
> >> then you have to say it's one of these and furiously deny that it's
> >> either of the other two.
> >> 
> >>   John
> > 
> > Well i would say i have a procedural programming style in Javascript,
> > sometimes i invoke functions most for stringhandling, and occasionally i
> > use objects mostly to confuse myself.... 
> 
> I agree.
> 

Finally we found a common ground LoL
Honestly i do admire all programmers persistence learning nonesense syntax ad nauseam, and i confess i am probably not up to it unless under pistol threat.

It can be lazyness but it can also be so simple that different personality types put emphasis upon different things within the datastream we as humans have to handle. Personally i have real difficult to learn blackbox behaviour "memorise" random data, so it could well be i have a problem to memorise, or simply that i or my brain chose to focus on other things.

> 
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#36719

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2019-06-01 01:10 -0700
Message-ID<e81f42bc-49b3-4752-a5a7-26423763da1b@googlegroups.com>
In reply to#36715
Den lördag 1 juni 2019 kl. 09:40:34 UTC+2 skrev Jonas Thörnvall:
> Den lördag 1 juni 2019 kl. 00:31:32 UTC+2 skrev Evertjan.:
> > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 31
> > May 2019 in comp.lang.javascript: 
> > 
> > > Den fredag 31 maj 2019 kl. 20:01:41 UTC+2 skrev John G Harris:
> > >> On Wed, 29 May 2019 10:24:17 -0700 (PDT), Julio Di Egidio
> > >> <julio@diegidio.name> wrote:
> > >> 
> > >> >On Wednesday, 29 May 2019 00:22:33 UTC+2, Thomas 'PointedEars' Lahn 
> > >> >wrote: 
> > >> >
> > >> >> (Unfortunately, regarding his code style Dr. Stockton 
> > >> >> appears to be stuck the world of Borland Pascal where such
> > >> >> distinctions need not be made because it is not an OOPL in the first
> > >> >> place.) 
> > >> >
> > >> >What a nonsensical statement: all the more so since JS is essentially
> > >> >NOT an OO language...
> > >> 
> > >> If you believe that
> > >>   a Functional language cannot be an OO language and cannot be a
> > >>     procedural language,
> > >>   an OO language cannot be a procedural language and cannot be a 
> > >>     Functional language,
> > >>   a procedural language cannot be a Functional language and cannot
> > >>     be an OO language,
> > >> 
> > >> then you have to say it's one of these and furiously deny that it's
> > >> either of the other two.
> > >> 
> > >>   John
> > > 
> > > Well i would say i have a procedural programming style in Javascript,
> > > sometimes i invoke functions most for stringhandling, and occasionally i
> > > use objects mostly to confuse myself.... 
> > 
> > I agree.
> > 
> 
> Finally we found a common ground LoL
> Honestly i do admire all programmers persistence learning nonesense syntax ad nauseam, and i confess i am probably not up to it unless under pistol threat.
> 
> It can be lazyness but it can also be so simple that different personality types put emphasis upon different things within the datastream we as humans have to handle. Personally i have real difficult to learn blackbox behaviour "memorise" random data, so it could well be i have a problem to memorise, or simply that i or my brain chose to focus on other things.
> 
> > 
> > 
> > -- 
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)

Do you guys feel it joyful, and an accomplishment when you memorised new syntax?
Well i don't, and that could be the problem. But i feel the joy when i accomplish to implement what i have planned. Unfortunately that sometimes require a bit more familiarity with the programming language and syntax then i actually master.

And then i am hangin lose, until i learn "or copy" it.

[toc] | [prev] | [next] | [standalone]


#36722

FromJohn G Harris <niam@jghnorth.org.uk.invalid>
Date2019-06-01 10:14 +0100
Message-ID<sfg4fed829th6vrit5lua7lp55l27c1ctb@4ax.com>
In reply to#36710
On Fri, 31 May 2019 11:21:47 -0700 (PDT), Jonas Thörnvall
<jonas.thornvall@gmail.com> wrote:

>Den fredag 31 maj 2019 kl. 20:01:41 UTC+2 skrev John G Harris:
>> On Wed, 29 May 2019 10:24:17 -0700 (PDT), Julio Di Egidio
>> <julio@diegidio.name> wrote:
>> 
>> >On Wednesday, 29 May 2019 00:22:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
>> >
>> >> (Unfortunately, regarding his code style Dr. Stockton 
>> >> appears to be stuck the world of Borland Pascal where such distinctions
>> >> need not be made because it is not an OOPL in the first place.)
>> >
>> >What a nonsensical statement: all the more so since JS is essentially
>> >NOT an OO language...
>> 
>> If you believe that
>>   a Functional language cannot be an OO language and cannot be a
>>     procedural language,
>>   an OO language cannot be a procedural language and cannot be a 
>>     Functional language,
>>   a procedural language cannot be a Functional language and cannot
>>     be an OO language,
>> 
>> then you have to say it's one of these and furiously deny that it's
>> either of the other two.
>> 
>>   John
>
>Well i would say i have a procedural programming style in Javascript, sometimes i invoke functions most for stringhandling, and occasionally i use objects mostly to confuse myself....

Sensible people know that a language can be any one, two, or all three
of those things. ECMAScript, alias JavaScript, is all three so
procedural programming is possible, but not recommended for
complicated programs.

  John

[toc] | [prev] | [next] | [standalone]


#36663

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2019-05-29 00:15 -0700
Message-ID<f303a7bf-78b4-48c4-8e96-dd3e72992961@googlegroups.com>
In reply to#36657
Den tisdag 28 maj 2019 kl. 14:38:34 UTC+2 skrev dr.j.r...@gmail.com:
> On Tuesday, 28 May 2019 11:03:03 UTC+1, R.Wieser  wrote:
> 
> > Forget what I said.   I just noticed that this is the javascript newsgroup, 
> > and not the VBScript one.  My bad.
> 
> No matter - your reply only needed translation :-
> 
>   S = "Banana"
>   eval("var " + S + " = [2, 9, +new Date()]")
>   Banana // is now a three-element array
> 
> -- 
>   (c) John Stockton, near London, UK.  Using Google Groups.           |
>  Mail: J.R.""""""""@physics.org - or as Reply-To, if any.             |

Hello I am a sucker at reading out syntax.
What does the follwing eval actually mean, it is not clear to me?
eval("dynamic" + i + " = val[i]");

Will it create an array named dynamic[] that can be accessed like any array?
When you put forward a solution, it would be nice with some words accompanying it, so a syntax slob like me can understand what the code actually achieve?

If it indeed do create a dynamic[] array, i will definitly use it.

[toc] | [prev] | [next] | [standalone]


#36664

From"R.Wieser" <address@not.available>
Date2019-05-29 09:35 +0200
Message-ID<qclco8$1v13$1@gioia.aioe.org>
In reply to#36663
Jonas,

> What does the follwing eval actually mean, it is not clear to me?
> eval("dynamic" + i + " = val[i]");

It will create a /variable/ with the name "dynamic" and whatever value(?) is 
in "i".   Assuming that "i" contains 42 than the name will be "dynamic42". 
After that it will simply copy the contents of "val[i]" into it.

> Will it create an array named dynamic[] that can be accessed like any 
> array?

Nope.

But that is easily solved.  John has already shown how to create an array. 
The only thing you need to do is to remove the initialisation values from it 
(rewritten to match your example) :

i=42
eval("var dynamic" + i + " = []");

(translates to 'var dynamic42 = []')

or, to use Johns example, but without initializing the array.

s = "banana"
eval("var " + s + " = []");

This will create an empty array with the name "banana", just like

var banana = [];

would.

Hope that helps.

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#36666

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2019-05-29 01:16 -0700
Message-ID<b250d694-fba8-4a58-bdbf-79a961422af2@googlegroups.com>
In reply to#36664
Den onsdag 29 maj 2019 kl. 09:35:46 UTC+2 skrev R.Wieser:
> Jonas,
> 
> > What does the follwing eval actually mean, it is not clear to me?
> > eval("dynamic" + i + " = val[i]");
> 
> It will create a /variable/ with the name "dynamic" and whatever value(?) is 
> in "i".   Assuming that "i" contains 42 than the name will be "dynamic42". 
> After that it will simply copy the contents of "val[i]" into it.
> 
> > Will it create an array named dynamic[] that can be accessed like any 
> > array?
> 
> Nope.
> 
> But that is easily solved.  John has already shown how to create an array. 
> The only thing you need to do is to remove the initialisation values from it 
> (rewritten to match your example) :
> 
> i=42
> eval("var dynamic" + i + " = []");
> 
> (translates to 'var dynamic42 = []')
> 
> or, to use Johns example, but without initializing the array.
> 
> s = "banana"
> eval("var " + s + " = []");
> 
> This will create an empty array with the name "banana", just like
> 
> var banana = [];
> 
> would.
> 
> Hope that helps.
> 
> Regards,
> Rudy Wieser

Ok thanks Rudy!

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.javascript


csiph-web