flyx / NimYAML

YAML implementation for Nim
https://nimyaml.org
Other
186 stars 36 forks source link

[Documentation] Simple example for loading a simple .yml file? #109

Closed rubyFeedback closed 2 years ago

rubyFeedback commented 2 years ago

Would it be possible to add a simple example how to load data from a yaml file?

I don't understand the advanced examples in nim yet. I am familiar with yaml files, but not with nim, so I struggle here. The examples at https://nimyaml.org/ seem to be written primarily for advanced users. And googling for working examples in nim is surprisingly hard; I wonder if nim is only used by advanced devs who already are way past such simple examples. To compare: both ruby and python provide very simple examples here. See https://zetcode.com/python/yaml/ and here for ruby https://yaml.org/YAML_for_ruby.html#simple_sequence

flyx commented 2 years ago

There are simple examples on the main page, but the order of the examples got scrambled for some reason. Search for Loading Nim objects from YAML. The simple Nim example is still more involved than the simple Python example, the reason being that NimYAML requires a target type to load the YAML into (since Nim is a statically typed language). A dict with arbitrarily typed entries is not possible here. Java's SnakeYAML can do Map<String, Object> but this is also not possible here because Nim is not hardcore tailored to OOP and doesn't have a general Object type.

The examples on the main page are generated from source code (so that the test suite can ensure that they actually do what they're supposed to be doing). The code doing that originally ordered them correctly, but something has changed since then so that it doesn't do that anymore. I need to investigate this.

flyx commented 2 years ago

I updated the webdocs and moved them on a new server. You may need to refresh and clear your DNS cache to see the updated version.

Simple examples are again on top now. You still can't escape from having to use static types. Please report back if this helps you, and if not, what problems you have with it.

flyx commented 2 years ago

Closing for lack of feedback.