Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STORE LENGTH OF vector #16

Merged
merged 2 commits into from
Mar 13, 2019
Merged

STORE LENGTH OF vector #16

merged 2 commits into from
Mar 13, 2019

Conversation

xvxx
Copy link
Collaborator

@xvxx xvxx commented Mar 13, 2019

In action:

DATA:
count IS NUMBER
names IS TEXT VECTOR
ages IS NUMBER VECTOR

PROCEDURE:
STORE 81 IN ages:0
STORE 75 IN ages:1
STORE 102 IN ages:2

STORE "Marilyn" IN names:0
STORE "Dillsworth" IN names:1
STORE "Rogert" IN names:2
STORE "Pepperberry" IN names:3

STORE LENGTH OF ages IN count
DISPLAY count " ages" 
DISPLAY " & " 
STORE LENGTH OF names IN count
DISPLAY count " names" CRLF

@Lartu
Copy link
Owner

Lartu commented Mar 13, 2019

Woah, neat! Thank you very much for your contribution! Much appreciated!

@Lartu Lartu merged commit ed25335 into Lartu:master Mar 13, 2019
@Lartu
Copy link
Owner

Lartu commented Mar 14, 2019

Hello! We've found a problem with STORE LENGTH OF. The thing is, when you look at a vector position and the value has not been initialized, it is initialized implicitly so the length of the vector grows by one. This, obviously, is very counter-intuitive and the solution to that issue is something that escapes this compiler, so I have two possible solutions:

One would be "COUNT INITIALIZED POSITIONS OF", that's just a rename of this funcion.

I'd rather just remove it for now. It's quite counter-intuitive and that goes against the philosophy of the language 😔

I'm sorry for not having realized this before.

@xvxx
Copy link
Collaborator Author

xvxx commented Mar 14, 2019

Ahh whoops! I didn't realize that.

Is your plan to keep that behavior for vectors? Because I'd think you could change the [] operators to return a default value if the key doesn't exist in the vector, if you wanted.

@Lartu
Copy link
Owner

Lartu commented Mar 14, 2019

I can look into that, but I believe it's not that easy for you cannot forsee on which side of the assignment operator the map will be.

@xvxx
Copy link
Collaborator Author

xvxx commented Mar 14, 2019

I see! I have been poking around and see what you mean, right now it's nice how flexible get_c_variable is in the compiler. You'd maybe have to check for the vector type and do an insert/push or something special in all the STORE code.

I am 👍 on removing this until there's a less confusing solution 👍

@Lartu
Copy link
Owner

Lartu commented Mar 14, 2019

Great, thank you! I'll check the code later and see what I can do, but checking the length of an LDPL VECTOR was not something I ever had in mind. Given that they aren't lineal, a size parameter may not be as expressive or useful as in other languages. Awk took the same decision. I'd rather keep and update a myvector.length variable, separately.

Thank you very much!

@xvxx
Copy link
Collaborator Author

xvxx commented Mar 15, 2019

👍 makes sense, I like this way of thinking, yes! I was originally reaching for STORE LENGTH OF vector to iterate over a list-like vector (and because the syntax was no addition) but I can track all that separately.

@Lartu
Copy link
Owner

Lartu commented Mar 15, 2019

Yay! That's the idea. In AWK you can't get the length of a vector and you end up using tracking variables. It's not the most comfortable thing in the world, but I find it to be consistent with the data structures used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants