-
Notifications
You must be signed in to change notification settings - Fork 261
Understand parsing JSON #599
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
Comments
Hi Voddan, I'll take a crack at some of it. If I use slightly incorrect terminology some-one please correct me, One of the abilities of Eve that tripped me (And I assume other people) up is the automatic assignment to unbound variables in a query if they share a name. You see this using json in the second line and a lot in the lookup. Once you get used to this part of the language though, it is a HUGE saver from writing boilerplate code. Response is a record, attached to the response attribute of the request record. It can have two attributes in this case, body or json. The http database is detecting that the content type is json and is helpfully running the body text though a json to eav function that turns the json into Eve data structures. The body text is still available and could be accessed using The second line is basically saying, "Query the database for records tagged both request and test-data that have a response which has a json section. Assign this json section to the variable json. The third line ( json = [#array] ) is an equivalence, it is a filter that says "The json record must have an #array tag". Since json can have both object and array formulation, it is a guard that the response has been turned into an array list. And finally the Lookup, you correct in that it hasn't been fully documented yet, and I'm not sure that I fully understand all its abilities (It's quite powerful). But essentially this is another blended query and assignment, it is saying "For each record in json, lookup the attributes and assign their values to the following unbound variables." I hope that mind-dump helped and if you have any further questions do not hesitate to ask either here or on the Google group. Regards, |
Thank you, @Cormac-Williams, that was very informative! Let me repeat what you said to see if I've got it right:
Are those correct? |
Hi Voddan, I think you've got it, except that the json in some ways is better thought of as the result of a query. It has already been parsed into an eve record structure for you. And can be further queried by the search section. i.e. to the search section works as a filter, even if you add it prior to the lookup line. I read the code to try and figure out whatever has not been documented and assume that it can change under me. There's also very useful discussion and links to examples that goes on in the https://groups.google.com/forum/#!forum/eve-talk group. The code for databases is in the src/runtime/databases and some further documentation on writing functions and databases is here. The @view functionality is written in Eve and is in the examples/view.eve file. Regards, |
Wow, cool! I've seen By the way, |
An undocumented language feature that the team is not sure will stay ;-) I've been thinking of it as a shorthand that says "At this point I've told you enough to identify a single unique record, use that.". But I could be completely wrong on that. Regards, |
Is there a way to work with |
Should be, post your example and what you are trying to do and I'll take a look. |
For example I've tried to use
This code has no effect thou |
Try And see what happens ;-) |
It works! Thanks! Then I don't understand why EVE did not stop me from committing a record with an untagged value. This must have been a error, or it must have worked. |
It did work, url was bound during the search phase and then committed to the @view database as part of the record. Try doing the same thing with an unbound attribute and you will get errors. |
No, it does not give me an error. The whole problem was that my initial code with |
Your initial code was the below? First block. This commits a single record tagged api-url and one attribute url with its corresponding value.
Second block,
In the search section, this searches for records tagged api-url and binds the url attributeof the record to the variable url.
You should get an error saying "Nothing is providing a value for url-this-wont-work" pretty much immediately. If this isn't how things are working and you are not getting this error, then post your full Eve file somewhere and I will try to recreate. Regards, |
I think I did not explain the situation clear enough. Yes, my code is what you wrote. This is my whole file, there was nothing besides those 2 blocks. When I said that it did not work I meant that there was no visible result. I would expect that But this is not true. My guess is that the first has a "type" like So my question is: why there is no error when committing a record with a member without a name? Is there a situation when it can be used? |
Ah, I understand. There is no formal type system underneath Eve at this time, everything is EAV (Entity, attribute, value) under the hood. This includes tags #value and #whatever, they get turned into a "tag" attribute with the values of the tag names in the datastore. So, if you do something like.
That is perfectly valid Eve code. The reason it didn't appear to begin with is that the view.eve file searches for records in the view database that are tagged #value and have an attribute value. Since your original commit to the @view database did not have a value, it didn't come up in the search. As to whether there is a situation it can be used? Well yes. The freedom to copy and augment only the data you are interested in from one place to another is to an extent the essence of programming and computers :-) Eve is just going about it in a much more "Database" and "Query" oriented fashion than most languages you come across. Regards, |
Sorry, I guess I din't get the last part. Does that meant that |
No, they are different. Both are records that have a tag #value, one has an attribute value, one has an attribute url. |
Sorry, I meant |
If you have url previously bound to value(s) then they are the same. the [#value url] version is simply syntactic sugar for the latter. |
Ok I see. This is extremely uncomfortable not to be able to freely choose names for my "local variables". 😞 |
You can, the syntactic sugar is for ease of use purposes, there is no requirement to do so. But how many times have you typed the same name on both sides of an assignment just to move one thing to another? |
@Cormac-Williams Thanks for explaining all this! |
@Cormac-Williams Thanks for filling in over the holiday! :P Your explanation was pretty much on point, so nothing really to add there. I would like to address a couple things though:
According to base Eve semantics, the record
Then Eve knows that the location of a #player doesn't contribute to that player's identity.
The pipe here is used in a similar way. We say
Just wanted to make sure there was no confusion here. If you are happy with the names the record uses, then you just pull it in:
Then you have the ability to use
And finally, you can re-name any attribute on a record to use as a local variable
So you have complete control over how you want to use names. Let us know if you have any more questions @voddan |
I'm going to close this, since I think your issue has been solved. |
Glad to help :-P |
@cmontella Thank you for the clarifications! I feel that at the moment EVE has a bunch of features that are rarely used (< 10% of apps). That may significantly hurt the learning curve. Maybe there are ways to generalise them somehow? For example EVE has very powerful tools for searchers, but in few cases you use Also could you please update https://witheve.github.io/assets/docs/SyntaxReference.pdf with all new operators / syntax constructs? This document at least tells me how different features are called, so I can try googling them. Right now nor |
@cmontella I have one more question if you don't mind. You pointed out that in my example the view blinks if used with Thanks |
Let's say I have some arbitrary json, can someone walk me through exploring it interactively with eve? Let's say I don't know anything about what the structure of the response will be ahead of time? |
I cannot understand this part in http://play.witheve.com/#/examples/http.eve
What happens in lines 2, 3, 4? I was unable to find any documentation regarding
lookup
. Also, what structure does a http response have? What is the meaning of[#array]
?Thank you for any help
The text was updated successfully, but these errors were encountered: