World: r3wp
[!REBOL3]
older newer | first last |
Endo 7-Jun-2011 [9062x3] | But then, the internal pointer changes because of the insert. >> head s/1 Trace: head (word) Trace: s/1 (path) Result: [[...] a b c] (block) |
>> index? s/1 Trace: index? (word) Trace: s/1 (path) Result: 3 (integer) | |
>> s/1 Trace: s/1 (path) == [b c] | |
Geomol 7-Jun-2011 [9065x2] | Now I'm in doubt! Need to think some more. :) |
I understand, what happens, that it's a position in a series, I try to insert earlier in the same series. I just find it a bit confusing, it works as it does. Woldn't it be more logical, if it's the position + 1, that is inserted in such cases? I think, this looks strange: >> s: [a b c d e f g h] == [a b c d e f g h] >> insert/only s find s 'd == [a b c d e f g h] >> s/1 == [c d e f g h] It seems more logical to me, if it does this: >> s: [a b c d e f g h] == [a b c d e f g h] >> insert/only s next find s 'd == [a b c d e f g h] >> s/1 == [d e f g h] | |
Ladislav 7-Jun-2011 [9067x2] | So, you prefer lists |
You need to realize, that there are implementation differences between lists and blocks, and that they are "enforced" by the properties of the respective datatypes. | |
Geomol 7-Jun-2011 [9069x2] | hm, could be. :) Nah, blocks are very cool for many things. I think, both blocks and lists are useful though. |
It's also interesting, that if /only isn't used, the result is what I first would expect: >> s: [a b c d e f g h] == [a b c d e f g h] >> insert s find s 'd == [a b c d e f g h] >> s == [d e f g h a b c d e f g h] | |
Ladislav 7-Jun-2011 [9071] | block: [1 2] index? block ; == 1 insert block 0 index? block ; == 1 list: make list! [1 2] index? list ; == 1 insert list 0 index? list ; == 2 |
Endo 7-Jun-2011 [9072x2] | without /only is more general use of course, but it is completely different. In your last example (Geomol) you get the values of a series and insert them into another series. |
with /only you get a "pointer" to a series and put that "pointer" into another series. (I know "pointer" is not a correct word for this but you got the idea) | |
Geomol 7-Jun-2011 [9074] | What if I want to insert the tail position of a series earlier in the same series? >> s: [1 2] == [1 2] >> insert/only s tail s == [1 2] >> s/1 == [2] >> insert/only s next tail s == [[...] 1 2] >> s/1 == [2] So that can't be done. |
Endo 7-Jun-2011 [9075] | So you could have a series which holds "pointers" to other some positions in another series, even a position in itself. |
Ladislav 7-Jun-2011 [9076] | s: make list! [1 2] insert/only s tail s s/-1 ; [] |
Geomol 7-Jun-2011 [9077] | Yes, works with list as expected. |
Ladislav 7-Jun-2011 [9078] | It is not hard to find out, why it cannot work with blocks the same way |
Geomol 7-Jun-2011 [9079] | It can't? Isn't that just a design desision? |
Ladislav 7-Jun-2011 [9080] | It can't |
Geomol 7-Jun-2011 [9081] | *decision* ok, can you explain why or give an example, that clearly show it? |
Ladislav 7-Jun-2011 [9082] | The above list example proves, that lists don't "know" their index, and have to calculate it every time, which means, that "index access" is slow. |
Geomol 7-Jun-2011 [9083] | I think, this is only a problem with blocks, if you insert a later position earlier in the same block. |
Ladislav 7-Jun-2011 [9084] | As opposed to that, blocks are designed for fast index access, so they have to "know" it, which means, that INSERT cannot change it |
Geomol 7-Jun-2011 [9085x2] | I don't think, INSERT have to change position of some index, it just have to insert the next position than the one given, and only if insert is earlier in the same series. |
I can't see, it shouldn't work. But we'll see... | |
Ladislav 7-Jun-2011 [9087x3] | I don't think, INSERT have to change position of some index - that formulation does not make sense to me |
index is a number | |
the one obtained using the INDEX? function | |
Geomol 7-Jun-2011 [9090] | I read you, as INSERT cannot change an index. I say, INSERT should just add 1 to the index number, it receives, and only in that special case. |
Ladislav 7-Jun-2011 [9091x2] | INSERT cannot do such a "harakiri" |
how could it? | |
Geomol 7-Jun-2011 [9093] | :) |
Ladislav 7-Jun-2011 [9094x3] | just realize, that index is a number, and every blocks remembers it |
if it did not, it would have to calculate it every time | |
and, since the index attribute is immutable, in fact, the INDEX function cannot change it | |
Geomol 7-Jun-2011 [9097] | I'm not talking about calculating every time and changing of indexes being hold by variables and such. I only suggest, that INSERT does this: If /only and if value being inserted is an index (or position or what we should call it) later in the same series, where we are inserting, add 1 to the index value and insert that. In all other cases carrie on as usual. |
Ladislav 7-Jun-2011 [9098] | THat is nonsense, it would be incompatible with the above example I wrote |
Geomol 7-Jun-2011 [9099] | I'm sorry, if it doesn't make sense. I sometimes find it easy to figure out such solutions but very difficult to explain it to others. :) I'll just go and implement it myself. |
Ladislav 7-Jun-2011 [9100x2] | You need to realize, that "insert/only a block into a block with the same head" has to be compatible with "insert/only a block into a block with distinct head" |
Otherwise you are asking for any kind of trouble you can invent. | |
Geomol 7-Jun-2011 [9102] | sure, and it's possible to test for that. |
Ladislav 7-Jun-2011 [9103] | Well, the only thing I can suggest you is to try it and see which incompatibilities you get. |
Andreas 7-Jun-2011 [9104x3] | Geomol, refering to your example above: >> s: [a b c d e f g h] == [a b c d e f g h] >> p: find s 'd == [d e f g h] >> insert s 42 == [a b c d e f g h] >> p == [c d e f g h] |
Extending this to your insert/only observation, the behaviour is perfectly consistent. | |
Whereas with your awful proposed insert/only-hack, it would not. | |
Geomol 7-Jun-2011 [9107] | I see no problem with your example. I'm surprised, you find my suggestion "awful". What's awful about this: >> s: [a b c d e f g h] == [a b c d e f g h] >> p: find s 'd == [d e f g h] >> insert/only s p == .... >> s/1 == [d e f g h] >> p == [c d e f g h] |
Kaj 7-Jun-2011 [9108] | John, remember our previous discussion, that indexes are not properties of series, but properties of series references. Therefore, it makes no sense to try to make a vector behave like a list, because any other references to the vector are unknown and thus it's impossible to make the behaviour for those references consistent |
Ladislav 7-Jun-2011 [9109] | The awful property is as follows: s: [a b c d e f g h] t: [a b c d e f g h] p: find s 'd insert/only s p insert/only t p same? first s p ; == false ! same? first t p ; == true |
Geomol 7-Jun-2011 [9110] | That's a strong point! |
Robert 10-Jun-2011 [9111] | I'm really wondering what's up with Carl. |
older newer | first last |