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


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

General compute language, syntax question

Started byjonas.thornvall@gmail.com
First post2016-02-29 05:45 -0800
Last post2016-03-03 00:26 -0800
Articles 7 — 4 participants

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


Contents

  General compute language, syntax question jonas.thornvall@gmail.com - 2016-02-29 05:45 -0800
    Re: General compute language, syntax question jonas.thornvall@gmail.com - 2016-02-29 05:58 -0800
      Re: General compute language, syntax question jonas.thornvall@gmail.com - 2016-02-29 06:25 -0800
        Re: General compute language, syntax question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-29 15:11 +0000
    Re: General compute language, syntax question Martin Honnen <mahotrash@yahoo.de> - 2016-02-29 15:47 +0100
    Re: General compute language, syntax question "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-03-02 18:14 -0800
      Re: General compute language, syntax question jonas.thornvall@gmail.com - 2016-03-03 00:26 -0800

#29725 — General compute language, syntax question

Fromjonas.thornvall@gmail.com
Date2016-02-29 05:45 -0800
SubjectGeneral compute language, syntax question
Message-ID<615c2e25-d8b6-4803-a157-b7ba748d1c71@googlegroups.com>
I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features 

"Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.

For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean". 

But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list. 

So if the current node i generate links for is x and i try to generate a link to  node z, and z's links exhausted i will add it to exhausted list.

And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.

So what i need is to know howto write "if list/array ***empty*** do {something}"

I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.

I think it is crazy that you can not do general comparissons of the type 
If in list/array
If not in list/array

But it is even more crazy that you can not check if list/array is empty, that is just madness.

[toc] | [next] | [standalone]


#29726

Fromjonas.thornvall@gmail.com
Date2016-02-29 05:58 -0800
Message-ID<93318b24-7815-4801-bea2-309e79c6f5dd@googlegroups.com>
In reply to#29725
Den måndag 29 februari 2016 kl. 14:46:07 UTC+1 skrev jonas.t...@gmail.com:
> I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features 
> 
> "Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.
> 
> For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean". 
> 
> But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list. 
> 
> So if the current node i generate links for is x and i try to generate a link to  node z, and z's links exhausted i will add it to exhausted list.
> 
> And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.
> 
> So what i need is to know howto write "if list/array ***empty*** do {something}"
> 
> I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.
> 
> I think it is crazy that you can not do general comparissons of the type 
> If in list/array
> If not in list/array
> 
> But it is even more crazy that you can not check if list/array is empty, that is just madness.

I mean for example Javascript tells me to use 

if (typeof array[index] !== 'undefined' && array[index] !== null) {

or this one

if (array[index] != null) {

I mean how do they come up with such convoluted syntax, do they pull it out of ass? Well one can always say it is needed because undefined not equal to null.

But would not if (array[index]==empty) suffice and be alot clearer?

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


#29727

Fromjonas.thornvall@gmail.com
Date2016-02-29 06:25 -0800
Message-ID<1df59a2c-61fd-4431-885c-70f12d15f678@googlegroups.com>
In reply to#29726
Den måndag 29 februari 2016 kl. 14:59:00 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 29 februari 2016 kl. 14:46:07 UTC+1 skrev jonas.t...@gmail.com:
> > I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features 
> > 
> > "Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.
> > 
> > For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean". 
> > 
> > But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list. 
> > 
> > So if the current node i generate links for is x and i try to generate a link to  node z, and z's links exhausted i will add it to exhausted list.
> > 
> > And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.
> > 
> > So what i need is to know howto write "if list/array ***empty*** do {something}"
> > 
> > I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.
> > 
> > I think it is crazy that you can not do general comparissons of the type 
> > If in list/array
> > If not in list/array
> > 
> > But it is even more crazy that you can not check if list/array is empty, that is just madness.
> 
> I mean for example Javascript tells me to use 
> 
> if (typeof array[index] !== 'undefined' && array[index] !== null) {
> 
> or this one
> 
> if (array[index] != null) {
> 
> I mean how do they come up with such convoluted syntax, do they pull it out of ass? Well one can always say it is needed because undefined not equal to null.
> 
> But would not if (array[index]==empty) suffice and be alot clearer?

I mean how utterly fucking stupid must one be to come up with a solution that require the programmer to check if the array[index] is empty what index? Index for 0 it doesn't exist? Or do they require me to loop thru an empty list how do you do that?

Would it not be alot of clearer to have a boolean empty flag upon the list/array, that is changed when you add elements?

arr=new Array();
if (arr==empty){//sure am here };
arr[x]="something";//
if (arr==empty) {//no way i got here};

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


#29729

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-02-29 15:11 +0000
Message-ID<87povflffk.fsf@bsb.me.uk>
In reply to#29727
jonas.thornvall@gmail.com writes:
<snip>
> I mean how utterly fucking stupid must one be to come up with a
> solution that require the programmer to check if the array[index] is
> empty what index? Index for 0 it doesn't exist? Or do they require me
> to loop thru an empty list how do you do that?

It's possible that you are using the wrong data type for the job (an
array is very different from a list, so if you need a list an array
might be a bad fit).

Anyway, if you are using the new ECMAScript you might find that

  !array.some(() => true)

does what you want or even (depending on how you handle deleted
elements) the much cheaper array.length == 0.  For example, if you use
push/pop/ shift/unshift to add and remove elements you'll find an
empty "list" has length zero.

-- 
Ben.

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


#29728

FromMartin Honnen <mahotrash@yahoo.de>
Date2016-02-29 15:47 +0100
Message-ID<nb1lma$cg6$1@news.albasani.net>
In reply to#29725
jonas.thornvall@gmail.com wrote:

> So what i need is to know howto write "if list/array ***empty*** do {something}"

Does

   if (array.length == 0) {
     //do something
   }

not implement what you want with Javascript?

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


#29780

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2016-03-02 18:14 -0800
Message-ID<cd4860f5-caa6-41d9-9727-fd87cb816e8e@googlegroups.com>
In reply to#29725
On Monday, February 29, 2016 at 7:46:07 AM UTC-6, jonas.t...@gmail.com wrote:
> I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features 

I'm making this as a general comment since you have a very high noise quotient in your posting. Coupled with the very large number of postings leaves most of us in a position of TLDR with your posts.

Don't take this as an insult, but I very much suggest reading an introductory text or two on Algorithms and to try and implement them directly instead of trying to discover the details through exploratory programming. It will answer many of the questions you tend to raise. Two suggestions:

1. Simple: "Algorithm Design"
<http://www.amazon.com/Algorithm-Design-Foundations-Analysis-Internet/dp/0471383651/ref=sr_1_sc_1?s=books&ie=UTF8&qid=1456971127&sr=1-1-spell&keywords=algorithm+design%2C+Goodritch>

2. Complex: "Introduction to Algorithms"
<http://www.amazon.com/Introduction-Algorithms-3rd-Thomas-Cormen/dp/0262033844/ref=sr_1_1?s=books&ie=UTF8&qid=1456971203&sr=1-1&keywords=introduction+to+algorithms>

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


#29785

Fromjonas.thornvall@gmail.com
Date2016-03-03 00:26 -0800
Message-ID<67b4b322-079d-44b8-b349-619dd127a399@googlegroups.com>
In reply to#29780
Den torsdag 3 mars 2016 kl. 03:14:20 UTC+1 skrev Michael Haufe (TNO):
> On Monday, February 29, 2016 at 7:46:07 AM UTC-6, jonas.t...@gmail.com wrote:
> > I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features 
> 
> I'm making this as a general comment since you have a very high noise quotient in your posting. Coupled with the very large number of postings leaves most of us in a position of TLDR with your posts.
> 
> Don't take this as an insult, but I very much suggest reading an introductory text or two on Algorithms and to try and implement them directly instead of trying to discover the details through exploratory programming. It will answer many of the questions you tend to raise. Two suggestions:
> 
> 1. Simple: "Algorithm Design"
> <http://www.amazon.com/Algorithm-Design-Foundations-Analysis-Internet/dp/0471383651/ref=sr_1_sc_1?s=books&ie=UTF8&qid=1456971127&sr=1-1-spell&keywords=algorithm+design%2C+Goodritch>
> 
> 2. Complex: "Introduction to Algorithms"
> <http://www.amazon.com/Introduction-Algorithms-3rd-Thomas-Cormen/dp/0262033844/ref=sr_1_1?s=books&ie=UTF8&qid=1456971203&sr=1-1&keywords=introduction+to+algorithms>

http://jt.node365.se/nodes12.html

[toc] | [prev] | [standalone]


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


csiph-web