Re: Delete the first entry of an array.
don't make me go all LISP on you...or APL On Sun, Mar 27, 2016 at 7:03 PM, Dr. Hawkinswrote: > On Sat, Mar 26, 2016 at 4:40 PM, Alex Tweedly wrote: > > > e, and hence be able to do completely dense arrays, just like Fortran > etc. > > (he said, making about 50 wild assumptions about a language he can't > find a > > spec for :-) > > > Just to throw gas on the flames (petrol for you cross-atlantans) . . . > > Fortran can have sparse arrays, far larger than memory or disk storage . . > . > > > -- > Dr. Richard E. Hawkins, Esq. > (702) 508-8462 > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > -- On the first day, God created the heavens and the Earth On the second day, God created the oceans. On the third day, God put the animals on hold for a few hours, and did a little diving. And God said, "This is good." ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: (way OT, WAS: )Re: Delete the first entry of an array.
On 3/27/2016 6:59 PM, Dr. Hawkins wrote: I've been out-crankied! LOL. But actually I think the final score is three out of four, so you are still in the running. :) -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: (way OT, WAS: )Re: Delete the first entry of an array.
On Sun, Mar 27, 2016 at 4:36 PM, Alex Tweedlywrote: > Hmmm ... not real Fortran. (that should be said in a deep, impressive > voice) > Real Fortran died when Fortran 77 took over :-( > I've been out-crankied! > > And, AFAIK, only those modern variants from (I think) Fortran90 onwards > have sparse arrays. > Yes, I designed the algorithm for my dissertation in Fortran 90, longing for some of the F95 features that weren't available yet. Sparse arrays would have been useful, except for the detail that the elements that I *was* generating in my search dwarfed the size of physical memory . . . -- Dr. Richard E. Hawkins, Esq. (702) 508-8462 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On Sat, Mar 26, 2016 at 4:40 PM, Alex Tweedlywrote: > e, and hence be able to do completely dense arrays, just like Fortran etc. > (he said, making about 50 wild assumptions about a language he can't find a > spec for :-) Just to throw gas on the flames (petrol for you cross-atlantans) . . . Fortran can have sparse arrays, far larger than memory or disk storage . . . -- Dr. Richard E. Hawkins, Esq. (702) 508-8462 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 27/03/2016 20:47, Ali Lloyd wrote: True - but sadly there's no effective way to filter those 523 entries to see only the ones that are relevant to a List type. One way to do this is to click the 'lists' filter in the tags section. Thanks. I had tried typing 'list' into the search box, which over-enthusiastically reduced the entries to only 7 :-) The tag works much better Thanks -- Alex. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
> True - but sadly there's no effective way to filter those 523 entries to > see only the ones that are relevant to a List type. One way to do this is to click the 'lists' filter in the tags section. On Sun, Mar 27, 2016 at 5:33 PM Alex Tweedlywrote: > > > On 27/03/2016 10:42, Peter TB Brett wrote: > > On 26/03/2016 23:40, Alex Tweedly wrote: > >> I haven't found (can't find) a spec for LCB, so I'm not sure exactly > >> what "proper lists" are - but I think maybe not quite what I meant. > > > > There's a spec in the "Guides" tab of the LC8 dictionary -- look for > > "LiveCode Builder Language Reference". > I see that, but the ONLY mention it makes of lists are: > - it is one of the Types > - it holds a "sequence of values" > - what a ListExpression is. > > > There's also a whole LCB dictionary section in the "Dictionary" tab > > that describes all the syntax relating to working with Lists. > True - but sadly there's no effective way to filter those 523 entries to > see only the ones that are relevant to a List type. > > > >> I was thinking of "proper arrays" :-) i.e. real, old-fashioned indexed > >> arrays - see Algol, Fortran, etc. > >> > >> So we would have > >> read access in constant time > >> write access in constant time > >> insertion complexity - there is no such thing as insertion :-) > > > > Yes. We're talking about the same thing. The LCB "List" datatype is > > this datastructure. > > > I suspect we're not quite talking about the same thing - I think 'proper > lists' are something more powerful than I was picturing, but can do > everything I am looking for - and a whole lot more. If I simply ignore > all that "more", then they do what I am hoping for. > > Many thanks for you patience explaining this. > I'll go start playing with LCB and try to ask harder questions :-) > > Thanks > -- Alex. > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 27/03/2016 10:42, Peter TB Brett wrote: On 26/03/2016 23:40, Alex Tweedly wrote: I haven't found (can't find) a spec for LCB, so I'm not sure exactly what "proper lists" are - but I think maybe not quite what I meant. There's a spec in the "Guides" tab of the LC8 dictionary -- look for "LiveCode Builder Language Reference". I see that, but the ONLY mention it makes of lists are: - it is one of the Types - it holds a "sequence of values" - what a ListExpression is. There's also a whole LCB dictionary section in the "Dictionary" tab that describes all the syntax relating to working with Lists. True - but sadly there's no effective way to filter those 523 entries to see only the ones that are relevant to a List type. I was thinking of "proper arrays" :-) i.e. real, old-fashioned indexed arrays - see Algol, Fortran, etc. So we would have read access in constant time write access in constant time insertion complexity - there is no such thing as insertion :-) Yes. We're talking about the same thing. The LCB "List" datatype is this datastructure. I suspect we're not quite talking about the same thing - I think 'proper lists' are something more powerful than I was picturing, but can do everything I am looking for - and a whole lot more. If I simply ignore all that "more", then they do what I am hoping for. Many thanks for you patience explaining this. I'll go start playing with LCB and try to ask harder questions :-) Thanks -- Alex. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 26/03/2016 23:40, Alex Tweedly wrote: I haven't found (can't find) a spec for LCB, so I'm not sure exactly what "proper lists" are - but I think maybe not quite what I meant. There's a spec in the "Guides" tab of the LC8 dictionary -- look for "LiveCode Builder Language Reference". There's also a whole LCB dictionary section in the "Dictionary" tab that describes all the syntax relating to working with Lists. I was thinking of "proper arrays" :-) i.e. real, old-fashioned indexed arrays - see Algol, Fortran, etc. So we would have read access in constant time write access in constant time insertion complexity - there is no such thing as insertion :-) Yes. We're talking about the same thing. The LCB "List" datatype is this datastructure. Peter -- Dr Peter BrettLiveCode Open Source Team LiveCode 2016 Conference https://livecode.com/edinburgh-2016/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 26/03/2016 07:35, Peter TB Brett wrote: On 25/03/2016 23:00, Alex Tweedly wrote: How about a Feature Exchange for adding arrays ? (i.e. not dictionaries, but actual arrays with numeric indices and linear access times) In LiveCode, we currently call these "proper lists". LiveCode arrays currently have O(log N) read and insertion complexity in the general case (which is better than linear). If we were to add proper lists, we would probably use an implementation with O(1) read and O(N) insertion complexity in the general case. Yes, sorry, I said it badly, leading to some confusion. I meant "linear access time" for accessing every element of the array in turn - i.e. (roughly) equivalent to "constant access time" for an individual access. If you need proper lists, LiveCode Builder already provides them with the "List" type. I haven't found (can't find) a spec for LCB, so I'm not sure exactly what "proper lists" are - but I think maybe not quite what I meant. I was thinking of "proper arrays" :-) i.e. real, old-fashioned indexed arrays - see Algol, Fortran, etc. So we would have read access in constant time write access in constant time insertion complexity - there is no such thing as insertion :-) OK, given that we would never want to require array declarations to define bounds, there might be some extra cost on extending the bounds, but that would be occasional, so we would in general have constant access time (for either read or write). And, of course, if it were done in LCB it would be even more advantageous because we would pre-define the data type, and hence be able to do completely dense arrays, just like Fortran etc. (he said, making about 50 wild assumptions about a language he can't find a spec for :-) Regards -- Alex. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
Peter TB Brett wrote: On 26/03/2016 14:18, Richard Gaskin wrote: Is there an estimate for when indexed arrays ("proper lists") may become available in LiveCode Script? Not currently on the roadmap. Given how frequently it's been requested for many years I was surprised I couldn't find an enhancement request for it in the RQCC, so I added one this morning: http://quality.livecode.com/show_bug.cgi?id=17236 -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 26/03/2016 14:18, Richard Gaskin wrote: Is there an estimate for when indexed arrays ("proper lists") may become available in LiveCode Script? Not currently on the roadmap. Peter -- Dr Peter BrettLiveCode Open Source Team LiveCode 2016 Conference https://livecode.com/edinburgh-2016/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
Peter TB Brett wrote: > On 25/03/2016 23:00, Alex Tweedly wrote: > >> How about a Feature Exchange for adding arrays ? (i.e. not >> dictionaries, but actual arrays with numeric indices and linear >> access times) > > In LiveCode, we currently call these "proper lists". > > LiveCode arrays currently have O(log N) read and insertion complexity > in the general case (which is better than linear). > > If we were to add proper lists, we would probably use an > implementation with O(1) read and O(N) insertion complexity in the > general case. > > If you need proper lists, LiveCode Builder already provides them with > the "List" type. Is there an estimate for when indexed arrays ("proper lists") may become available in LiveCode Script? -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 25/03/2016 23:00, Alex Tweedly wrote: How about a Feature Exchange for adding arrays ? (i.e. not dictionaries, but actual arrays with numeric indices and linear access times) In LiveCode, we currently call these "proper lists". LiveCode arrays currently have O(log N) read and insertion complexity in the general case (which is better than linear). If we were to add proper lists, we would probably use an implementation with O(1) read and O(N) insertion complexity in the general case. If you need proper lists, LiveCode Builder already provides them with the "List" type. Peter -- Dr Peter BrettLiveCode Open Source Team LiveCode 2016 Conference https://livecode.com/edinburgh-2016/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
Alex Tweedly wrote: > How about a Feature Exchange for adding arrays ? (i.e. not > dictionaries, but actual arrays with numeric indices and linear > access times) lulz. Cute, but of course associative arrays are indeed a type of array. But yes, it would be nice to also support indexed arrays. I have a vague recollection of Mark Waddingham noting somewhere back in the Engine Contributors section of the forums or a bug report that wouldn't be hard to do. May be my aging memory, though -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 25/03/2016 08:03, Peter TB Brett wrote: Hi Peter, LiveCode arrays are actually dictionaries (more like JavaScript objects than JavaScript arrays). There aren't currently any push/pop syntax for LiveCode arrays. ... I hope that's helpful. Would anyone be interested in a Feature Exchange for adding some new array operators (such as push and pop) to the language? Peter How about a Feature Exchange for adding arrays ? (i.e. not dictionaries, but actual arrays with numeric indices and linear access times) -- Alex. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
Leave things as they are, delete the first element, and keep track of an offset value that you use to grab array elements. If your array starts at 1, and you haven't deleted any elements from the front, the offset is 0. If you delete 2 items, from the front, the offset is 2. If you want to access the 4th element, it would be arrayval[itemnum+offset] You could generate the offset by grabbing the keylist, sorting it, and grabbing the first key - 1 (or use min() -1) but it would probably be far more efficient to just keep track as you go. You could keep the offset value in the array too. Of course, this doesn't help if you are removing elements from the middle of the numerically indexed array too. (in which case it would just make sense to keep a sorted list of keys and preform duplicate operations on the list. Then you can use line 3 of the keylist as your array key for the proper item. Having said all that, I'm all for a feature exchange to make this sort of thing easier. Yes please! (I don't have much discretionary spending moola, but this one would garner some of it) On Fri, Mar 25, 2016 at 4:25 AM, Peter W A Woodwrote: > Thanks Kay > > > On 25 Mar 2016, at 17:22, Kay C Lan wrote: > > > > On Fri, Mar 25, 2016 at 3:33 PM, Peter W A Wood > wrote: > > > >> delete pList[“numbers”] 1 ## Is > this the correct syntax? > > > > No. Shouldn't it be: > > > > delete variable pList["number"][1] > > > > At least that works for me, although in your case I think, if I > > understand it correctly, I'd tackle the problem by: (suedo-code) > > > > repeat with x = 2 to the number of keys in firstArray > > put firstArray[x] into secondArray[x - 1] > > end repeat > > put secondArray into firstArray > > > I do something like this at the moment. I was trying to see if there was > an easier/quicker way. > > Kind regards > > Peter > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Feature Exchange for Array extensions (Was Re: Delete the first entry of an array.)
On 3/25/2016 4:03 AM, Peter TB Brett wrote: > Would anyone be interested in a Feature Exchange for adding some new > array operators (such as push and pop) to the language? > > Peter I'm not very interested in a push and pop functions, but what I have been wanting for quite some time is really good row and column operations on 2 dimensional numerically index arrays. LC Bugzilla entries 670, 4623, 7243, and 9950 are a few enhancements requests related to this need I really want to have chunk expressions for a 2D array, such as "put row 3 of somearray into tVar" OR, the really handy one, "put column 5 of myArray into AColumn" and even things like "get word 2 of first row of last column of anotherarray" Similar with "delete row 7" or "put empty into column 6" or " put 0 into column 6" (replace all cells in column 6 with zero). Also an associated modifications to "split" and "combine" to turn delimited (typically tab and cr) data into a 2D numerically indexed array and 2D numerically index arrays into delimited data Obviously, these functions can be coded (and have been) as LC script handlers, but I find myself working with table data frequently enough that I really would like them to be part of the engine. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
Thanks Kay > On 25 Mar 2016, at 17:22, Kay C Lanwrote: > > On Fri, Mar 25, 2016 at 3:33 PM, Peter W A Wood wrote: > >> delete pList[“numbers”] 1 ## Is this >> the correct syntax? > > No. Shouldn't it be: > > delete variable pList["number"][1] > > At least that works for me, although in your case I think, if I > understand it correctly, I'd tackle the problem by: (suedo-code) > > repeat with x = 2 to the number of keys in firstArray > put firstArray[x] into secondArray[x - 1] > end repeat > put secondArray into firstArray I do something like this at the moment. I was trying to see if there was an easier/quicker way. Kind regards Peter ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On Fri, Mar 25, 2016 at 3:33 PM, Peter W A Woodwrote: > delete pList[“numbers”] 1 ## Is this > the correct syntax? No. Shouldn't it be: delete variable pList["number"][1] At least that works for me, although in your case I think, if I understand it correctly, I'd tackle the problem by: (suedo-code) repeat with x = 2 to the number of keys in firstArray put firstArray[x] into secondArray[x - 1] end repeat put secondArray into firstArray ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
Peter Thanks for the suggestions. > On 25 Mar 2016, at 16:03, Peter TB Brettwrote: > > On 2016-03-25 08:33, Peter W A Wood wrote: >> I have an array which contains a second array. (myArray[“numbers”][]). >> ... >> automatically change the index of the remaining entries? > > Hi Peter, > > LiveCode arrays are actually dictionaries (more like JavaScript objects than > JavaScript arrays). There aren't currently any push/pop syntax for LiveCode > arrays. Thanks for the confirmation as I wasn’t sure that was the case for all arrays due to the existence of the extents function. > I would recommend two things: > > 1) Arrange your algorithm so that you extract things one-by-one from the > _end_ of the numbered array, rather than the start. This is more efficient! It is not possible in this case as the order of the elements is significant. I use a different function to remove the last element of the array. > > 2) Alternatively, you can shift everything along, which will be slow: > > function PopStart @xArray > local tLength, tItem, tKey > > put the number of elements in xArray into tLength > if tLength is 0 then return empty > > put xArray[1] into tItem > > repeat with tKey = 2 to tLength > put xArray[tKey] into xArray[tKey - 1] > end repeat > delete xArray[tLength] > > return tItem > end PopStart This is what I am currently having to do but am not too worried yet as I believe in the “Getting it working, getting it working correctly, getting working quickly approach”. > I hope that's helpful. Thanks for the suggestions. Kind regards Peter ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete the first entry of an array.
On 2016-03-25 08:33, Peter W A Wood wrote: I have an array which contains a second array. (myArray[“numbers”][]). The numbers array is a traditional array with elements 1..n. I want to remove the first element of the numbers array and shuffle all the others up. Is there a simple way of doing this in LiveCode (equivalent to the shift() function in JavaScript)? I looked in the dictionary and found delete but couldn't get it to work, perhaps because I am trying to do this in a function that takes the array as an argument. The essence of the function is: function shift @pList local tItem put pList[“numbers”][1] into tItem delete pList[“numbers”] 1 ## Is this the correct syntax? return tItem end shift If I can get delete to remove the first element of the array, will it automatically change the index of the remaining entries? Hi Peter, LiveCode arrays are actually dictionaries (more like JavaScript objects than JavaScript arrays). There aren't currently any push/pop syntax for LiveCode arrays. I would recommend two things: 1) Arrange your algorithm so that you extract things one-by-one from the _end_ of the numbered array, rather than the start. This is more efficient! Then you would do something like: function PopEnd @xArray local tLength, tItem put the number of elements in xArray into tLength if tLength is 0 then return empty put xArray[tLength] into tItem delete xArray[tLength] return tItem end PopEnd 2) Alternatively, you can shift everything along, which will be slow: function PopStart @xArray local tLength, tItem, tKey put the number of elements in xArray into tLength if tLength is 0 then return empty put xArray[1] into tItem repeat with tKey = 2 to tLength put xArray[tKey] into xArray[tKey - 1] end repeat delete xArray[tLength] return tItem end PopStart 3) Another option, if you don't care about what order you get your values in, is to remove an item from anywhere, cheaply, by moving the last item in the list on top of the one you've removed: function RemoveAt @xArray, pIndex local tLength, tItem if pIndex is not among the keys of xArray then return empty put the number of elements in xArray into tLength put xArray[pIndex] into tItem put xArray[tLength] into xArray[pIndex] delete xArray[tLength] return tItem end RemoveAt I hope that's helpful. Would anyone be interested in a Feature Exchange for adding some new array operators (such as push and pop) to the language? Peter -- Dr Peter BrettLiveCode Open Source Team LiveCode 2016 Conference https://livecode.com/edinburgh-2016/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode