-
Notifications
You must be signed in to change notification settings - Fork 26
Creating a vector from an array list instead of a seq #18
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
Conversation
@slipset @marcomorain LGTM. |
@narkisr You might want to capture this behavior in the tests. |
@narkisr Thanks! I'd really appreciate it if you added a test so that we don't inadvertently break this in the future. |
I personally would prefer just a test with |
Hi @borkdude and @slipset after taking a look into at the existing tests it made more sense to me to change them and use get instead of nth, this forces the returned parsed value to be a vector (a seq will return nil). As a side note prior to this change using nth in this context had linear runtime (instead of o(1)) |
Hi @borkdude I don't mind going that route, but I see two main downsides:
Happy to change it any case, just wanted to point out my way of thinking on this :) |
@narkisr The title of this issue is "Creating a vector from an array list instead of a seq" If that is the intent, I think it's better to explicitly test this and make only the minimal changes to the code-base to test this by adding a test, while preserving the existing tests. |
06a9dff
to
7c1f7c7
Compare
Ok, cool just made the change let me know if any thing else is required Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@slipset It seems the tests broke on master:
Any reason the tests aren't run for PRs? |
@slipset I reverted the commit and that fixed the tests again. It would be nice if PRs were tested before they were merged. |
@slipset @narkisr It seems the recursive test broke, but it also seems that it has an infinite recursion. When realizing this, you get a stackoverflow. I'm not sure if the test should maybe change, or if laziness was intended to work like this. Even when taking the first element from the recursive result, you get a stackoverflow. |
The recursive test was added by @erichaberkorn in #13. Could you comment on this? |
Hi @borkdude just checked again that the tests passed on my branch (iv ran them locally): $ lein test
Compiling 1 source files to /home/re-ops/code/clj-yaml/target/classes
lein test clj-yaml.core-test
Ran 25 tests containing 50 assertions.
0 failures, 0 errors. Not sure what I am missing here |
@narkisr That's pretty weird. I get the same error as on master in CI. |
@narkisr Can you try: |
Hi @borkdude just did and got the same result:
Maybe our JVM is different? I'm using Amazon corretto: $ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment Corretto-8.252.09.1 (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM Corretto-8.252.09.1 (build 25.252-b09, mixed mode) Maybe the default stack sizes are different |
|
So, Since we can have infinite recursive structures in yaml (TIL), I guess |
Another option is to enable seqs only when using the recursive flag and document this (use vecs in the standard case), I'm not sure how common recursive yamls are in the wild (could be wrong though) BTW this still doesn't explain why it seems to be working on JDK 8 :) |
I'm not overly enthused about changing types of things depending on options passed. |
Thank you for your work on this, too bad it wasn't really feasible. |
@slipset What is the usefulness of an infinitely recursive YAML? I could not even do |
@slipset I am referring to this test: (def recursive-yaml "
---
&A
- *A: *A
")
(deftest allow-recursive-works
(is (thrown-with-msg? YAMLException #"Recursive" (parse-string recursive-yaml)))
(is (parse-string recursive-yaml :allow-recursive-keys true))) Calling |
I guess that's just taken from the snakeyaml docs
https://bitbucket.org/asomov/snakeyaml/wiki/Documentation Which doesn't quite explain how infinitely recursive objects are to be handled. |
A small change that fixes the way java.util.ArrayList is handled, right now when you parse a yml string that has an array you get back a seq, this break the expected contract since you can't access items within that array using an index for example:
The environment variables are parsed as a seq, this breaks the expected contract with the yml input (which is an array):
After this fix the result will be:
Thanks