{"action":"closed","issue":{"url":"https://api.github.com/repos/gnudatalanguage/gdl/issues/236","repository_url":"https://api.github.com/repos/gnudatalanguage/gdl","labels_url":"https://api.github.com/repos/gnudatalanguage/gdl/issues/236/labels{/name}","comments_url":"https://api.github.com/repos/gnudatalanguage/gdl/issues/236/comments","events_url":"https://api.github.com/repos/gnudatalanguage/gdl/issues/236/events","html_url":"https://github.com/gnudatalanguage/gdl/issues/236","id":316123317,"node_id":"MDU6SXNzdWUzMTYxMjMzMTc=","number":236,"title":"Empty list or hash references don't survive an array placement.","user":{"login":"slayoo","id":89685,"node_id":"MDQ6VXNlcjg5Njg1","avatar_url":"https://avatars2.githubusercontent.com/u/89685?v=4","gravatar_id":"","url":"https://api.github.com/users/slayoo","html_url":"https://github.com/slayoo","followers_url":"https://api.github.com/users/slayoo/followers","following_url":"https://api.github.com/users/slayoo/following{/other_user}","gists_url":"https://api.github.com/users/slayoo/gists{/gist_id}","starred_url":"https://api.github.com/users/slayoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slayoo/subscriptions","organizations_url":"https://api.github.com/users/slayoo/orgs","repos_url":"https://api.github.com/users/slayoo/repos","events_url":"https://api.github.com/users/slayoo/events{/privacy}","received_events_url":"https://api.github.com/users/slayoo/received_events","type":"User","site_admin":false},"labels":[{"id":963618077,"node_id":"MDU6TGFiZWw5NjM2MTgwNzc=","url":"https://api.github.com/repos/gnudatalanguage/gdl/labels/!NULL","name":"!NULL","color":"Fec16e","default":false},{"id":921987123,"node_id":"MDU6TGFiZWw5MjE5ODcxMjM=","url":"https://api.github.com/repos/gnudatalanguage/gdl/labels/experimental-feature","name":"experimental-feature","color":"8173c5","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-04-20T04:23:46Z","updated_at":"2018-06-15T21:53:02Z","closed_at":"2018-06-15T21:53:02Z","author_association":"MEMBER","body":"As reported by @maynardGK on SF.net (https://sourceforge.net/p/gnudatalanguage/bugs/696/):\r\n\r\n\r\n\r\nEmpty lists (or hashes) become nullObject when stuck into an array\r\n\r\nThis may be happening because somewhere a \"p->N_Elements == 0\" symptom\r\nimplies a null object. But N_Elements is overloaded to be # list/table elements (=0).\r\nSo when the object reference of an empty list is put into an (OBJ)array, its identity is lost.\r\n\r\n```\r\nBelow, \"L\" is a populated list and \"k\" is empty:\r\nGDL>L=list(indgen(4)) & k=list()\r\nGDL> print,obj_isa(L,'list')\r\n1\r\nGDL> print,obj_isa([L,L,L],'list')\r\n1 1 1\r\nGDL> print,obj_isa([L,L,L,k],'list')\r\n1 1 1 0\r\nGDL> print,obj_isa(k,'list')\r\n0\r\nGDL> help,k\r\nK LIST <ID=4 N_ELEMENTS=\"0\">\r\nGDL> ii=objarr(3)\r\nGDL> ii[0]=L & ii[1]=k & ii[2]=L\r\nGDL> help,ii[0],ii[1],ii[2]\r\n<Expression> LIST <ID=3 N_ELEMENTS=\"1\">\r\n<Expression> OBJREF = <NullObject>\r\n<Expression> LIST <ID=3 N_ELEMENTS=\"1\">\r\n```\r\n\r\nProbably the main answer is that the LIST() routine doesn't make a proper object;\r\nthe object pointer isn't assigned to the array because it is malformed in some manner.\r\n\r\nThis is probably specific to LIST and HASH types?\r\n```\r\nGDL> tt=objarr(4)\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    OBJREF    = <NullObject>\r\n<Expression>    OBJREF    = <NullObject>\r\n<Expression>    OBJREF    = <NullObject>\r\n<Expression>    OBJREF    = <NullObject>\r\nGDL> for k=0,3 do tt[k]=l\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\nGDL> help,lgdl\r\nLGDL            LIST      <ID=1  N_ELEMENTS=4>\r\nGDL> for k=0,3 do tt[k]=lgdl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=10  N_ELEMENTS=1>\r\n```\r\n\r\nEither 1. 0 elements or 2. object produced in the LIST() routine seem to be where the handling fails:\r\n```\r\nGDL> lgdl=obj_new('list',length=2)\r\nGDL> help,lgdl\r\nLGDL LIST <ID=11 N_ELEMENTS=\"0\">\r\nGDL> for k=0,3 do tt[k]=lgdl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression> OBJREF = <NullObject>\r\n<Expression> OBJREF = <NullObject>\r\n<Expression> OBJREF = <NullObject>\r\n<Expression> OBJREF = <NullObject>\r\nGDL> lgdl.add,1\r\nGDL> for k=0,3 do tt[k]=lgdl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"1\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"1\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"1\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"1\">\r\nGDL> lgdl.add,2\r\nGDL> for k=2,3 do tt[k]=lgdl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\nGDL> newl=obj_new('list',1)\r\nGDL> help,newl\r\nNEWL LIST <ID=12 N_ELEMENTS=\"0\">\r\nGDL> newl.add,1\r\nGDL> for k=0,1 do tt[k]=newl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression> LIST <ID=12 N_ELEMENTS=\"1\">\r\n<Expression> LIST <ID=12 N_ELEMENTS=\"1\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\nGDL> l=list(indgen(3),/extract)\r\nGDL> for k=2,3 do tt[k]=l\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression> LIST <ID=12 N_ELEMENTS=\"1\">\r\n<Expression> LIST <ID=12 N_ELEMENTS=\"1\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\n<Expression> LIST <ID=11 N_ELEMENTS=\"2\">\r\nGDL> help,l\r\nL LIST <ID=13 N_ELEMENTS=\"3\">\r\n```\r\n\r\nGood news: problem is understood ( at least, solution is possible).\r\nBad news: solution requires some surgery.\r\n\r\nAs I suspected in OP, changing the meaning of ->N_Elements() for the LIST and HASH\r\nobject cases is why these objects do not behave like other objects. This specification is what\r\nthe code should return when one does N_ELEMENTS( <list or=\"\" hash=\"\" object=\"\">) and also the answer in the return from SIZE( <list or=\"\" hash=\"\" object=\"\">). However it was implemented internally at a fundamental level - in the definition routine (datatypes.cpp) itself - which breaks the behavior\r\nof these objects when run through the generalized code.\r\n\r\nIn my code I've experimentally reverted the N_Elements() method to be the standard as for any object, and implemented the IDL functions N_ELEMENTS() and SIZE() such that the special cases of list or hash objects induce a modified result. Since the help procedure already looked directly at the count parameter it was already correct.\r\n\r\nlist.cpp\r\nhash.cpp\r\nprognode_expr.cpp\r\nbasic_fun.cpp\r\nbasic_fun_jmg.cpp\r\n\r\n```\r\nGDL> .rnew\r\nInteractive RUN not implemented yet.\r\nGDL> tt=objarr(4)\r\nGDL>  lgdl=obj_new('list')\r\n gdl_OBJECT_Init!\r\nGDL> help,lgdl\r\nLGDL            LIST      <ID=40  N_ELEMENTS=0>\r\nGDL> for k=0,3 do tt[k]=lgdl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=0>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=0>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=0>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=0>\r\nGDL> lgdl.add,1\r\nGDL> for k=0,3 do tt[k]=lgdl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=1>\r\nGDL> lgdl.add,2\r\nGDL> for k=2,3 do tt[k]=lgdl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=2>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=2>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=2>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=2>\r\nGDL> newl=obj_new('list')\r\n gdl_OBJECT_Init!\r\nGDL> help,newl\r\nNEWL            LIST      <ID=41  N_ELEMENTS=0>\r\nGDL> newl.add,1\r\nGDL> for k=0,1 do tt[k]=newl\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    LIST      <ID=41  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=41  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=2>\r\n<Expression>    LIST      <ID=40  N_ELEMENTS=2>\r\nGDL> l=list(indgen(3),/extract)\r\nGDL> for k=2,3 do tt[k]=l\r\nGDL> for k=0,3 do help,tt[k]\r\n<Expression>    LIST      <ID=41  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=41  N_ELEMENTS=1>\r\n<Expression>    LIST      <ID=42  N_ELEMENTS=3>\r\n<Expression>    LIST      <ID=42  N_ELEMENTS=3>\r\nGDL> help,l\r\nL               LIST      <ID=42  N_ELEMENTS=3>\r\nGDL> tt[0].count()\r\n           1\r\nGDL> help,l\r\nL               LIST      <ID=42  N_ELEMENTS=3>\r\nGDL> jj=list()\r\nGDL> help,jj\r\nJJ              LIST      <ID=43  N_ELEMENTS=0>\r\nGDL> jj.count()\r\n           0\r\n```"}}
{"actor":{"display_login":"slayoo"}}