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

Implement hasKey resource #400

Closed
czerwinskilukasz1 opened this issue Jul 17, 2020 · 10 comments · Fixed by #413
Closed

Implement hasKey resource #400

czerwinskilukasz1 opened this issue Jul 17, 2020 · 10 comments · Fixed by #413
Assignees
Labels
AskScript ./src/askscript/** AskVM ./src/askvm/** bug Something isn't working first-timers-only good first issue Good for newcomers help wanted Extra attention is needed type:resources related to AskVM resources
Milestone

Comments

@czerwinskilukasz1
Copy link
Collaborator

I wanted to write a piece of code that in Javascript looks like this:

if (!(a in leftMostPosition)) {
   leftMostPosition[a] = i;
}

Alas, I couldn't find any way to express it, because I didn't find a resource for it.
Please note that comparing leftMostPosition[a] with any value would not work as there is no undefined value in AskScript, only null, which could be a legitimate value of leftMostPosition[a].

@czerwinskilukasz1 czerwinskilukasz1 added AskScript ./src/askscript/** bug Something isn't working discussion A discussion is taking place, please don't work on it yet question Further information is requested labels Jul 17, 2020
@czerwinskilukasz1
Copy link
Collaborator Author

@mhagmajer

@mhagmajer
Copy link
Contributor

@czerwinskilukasz1 would the following make sense? We would need a hasKey resource for that

if (not(leftMostPosition:hasKey('a'))) {
   leftMostPosition[a] = i;
}

@czerwinskilukasz1
Copy link
Collaborator Author

hasKey sounds good to me. Renaming the task.

@czerwinskilukasz1 czerwinskilukasz1 changed the title [AskScript] How to check if a key exists in an object? Implement hasKey resource Jul 17, 2020
@czerwinskilukasz1 czerwinskilukasz1 added AskVM ./src/askvm/** type:resources related to AskVM resources first-timers-only good first issue Good for newcomers help wanted Extra attention is needed and removed discussion A discussion is taking place, please don't work on it yet question Further information is requested labels Jul 17, 2020
@czerwinskilukasz1
Copy link
Collaborator Author

Task:

Implement a hasKey resource. All list-related resources live in src/askvm/resources/list directory. Check other resources from the directory to grasp how they work.

@cpelican
Copy link
Contributor

cpelican commented Jul 21, 2020

Hi, I would be interested in submitting a pr for this issue, is it fine with you? Thanks!

@czerwinskilukasz1
Copy link
Collaborator Author

Hello @cpelican , it sounds awesome!

@czerwinskilukasz1
Copy link
Collaborator Author

czerwinskilukasz1 commented Jul 21, 2020

@cpelican, the issue is yours.
In addition to creating code to hasKey, please write also a test file (or a couple) in AskScript language in src/askscript/__tests__/07-arrays.
Let me know if you have any questions. We would love to hear feedback, e.g. if we are missing some documentation or guides for new contributors.

@cpelican
Copy link
Contributor

cpelican commented Jul 23, 2020

Hi @czerwinskilukasz1, @mhagmajer, I would have 2 questions:

  • I just added tests in src/askscript/__tests__/07-arrays, but before that i had noticed there were tests in askvm/resources/list/, so i had added some tests also there. Would you prefer if all tests were in the same directory or do these both places have different purposes?
  • The place where the code belongs indicates me this resource should apply to a list or array. But the use case of this issue made me think that this could be used for objects as well. Would you like it to work only on arrays or also on objects?
    Thanks!

@czerwinskilukasz1
Copy link
Collaborator Author

czerwinskilukasz1 commented Jul 26, 2020

Hi @cpelican ,

Hi @czerwinskilukasz1, @mhagmajer, I would have 2 questions:

  • I just added tests in src/askscript/__tests__/07-arrays, but before that i had noticed there were tests in askvm/resources/list/, so i had added some tests also there. Would you prefer if all tests were in the same directory or do these both places have different purposes?

So, tests in src/askscript/__tests__ are testing AskScript language, while tests in src/askvm/**/__tests__ test more low-level AskVM resources and the code is written in AskCode. Think of AskCode as an "assembler" for AskVM, while AskScript is a user-facing language (like C# or Javascript). Here is a diagram showing how different they look:
askQL-diagram

Also, tests in AskCode we write are usually much much shorter, limited to just one expression, while tests in AskScript tend to be a complete program.

  • The place where the code belongs indicates me this resource should apply to a list or array.

This is a good remark. I would save the resource in src/askvm/resources/list for now, but be prepared @mhagmajer might propose a better place after you create your PR.

But the use case of this issue made me think that this could be used for objects as well. Would you like it to work only on arrays or also on objects?

Great question. Yeah, I should have be more clear. I meant both arrays and objects.

@cpelican
Copy link
Contributor

@czerwinskilukasz1 ok, thank you for your answer!

@czerwinskilukasz1 czerwinskilukasz1 added this to the v1.3 milestone Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AskScript ./src/askscript/** AskVM ./src/askvm/** bug Something isn't working first-timers-only good first issue Good for newcomers help wanted Extra attention is needed type:resources related to AskVM resources
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants