-
Notifications
You must be signed in to change notification settings - Fork 2
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
Standard library documentation #1
Conversation
Preview available here https://benjaminnavarro.github.io/Book/12-standard-library.html |
Looks great! 😁 |
I started with the IO module. Could you tell me if you like it like this? I'm still unsure about the presentation of the functions signature. Do you prefer a leading or trailing return type? Should I also specify the type of the arguments if it is relevant? |
Ooh! It looks fantastic! Far better than what I'd have come up with, that's for sure! 😱 Also, I wonder if there is some tool (besides doxygen) that could parse and auto generate markdown from c++ source files. In that case, we could simply make and update the function reference while working on it to avoid a lot of manual work. Do you know of any software of that sorts? If not, perhaps we could employ doxygen, or if worthful, create a translator (from C++ comments to markdown) in Feral itself 🤔. What are your thoughts on this? |
Glad that you like it 😃 I'll add the types, no problem. I first thought about autogenerating the doc from source code comments but I don't know of a tool which can generate markdown files (Doxygen output is HTML and LaTeX only I think). Moreover, it is easier for people to contribute to the documentation if the only thing they have to do is fork the Book repo, make some changes (can be done from GitHub directly) and create a PR. And they don't have to mess with the source code, which is probably a good point. This is more or less what they do for the Godot game engine, with the docs being on a separate repo and generated (sphinx) based on a mix of hand written and autogenerated I don't known, I don't have a perfect answer for all of this, lot of possibilities... |
Oh yes! That seems to be the best option. Have a proper document in the book and a (much) smaller autogenerated API reference in the source code. |
You're welcome! I just pushed updates for the IO module. |
Ooh! Looks really nice! Amazing work!! |
Just quick question, what are the native type names? Here I can see that each type is defined with and without a trailing |
okay, so... |
It does, thanks. So I should use the _t variant to document the types in the API? |
no, since |
Great updates! A couple things though:
Again incredible work! Thanks a bunch! ❤️ |
|
wow! cool work on the By the way, how has been your experience understanding the language till now? Thanks for the fantastic work 😁 |
You're welcome! I find examples usually more important than the text surrounding them and often what people will look at first, so I focus on that a bit more than the rest. For now, with my (I hope) good C++ knowledge I can follow quite easily what's going on in the std but for things really language related, I often have to test things to see what works and what doesn't because the docs are still missing 😄 EDIT: I just looked at map.new() and I find it strange to pass all the key/value pairs like |
That's cool 😁. Glad to know that the C++ codebase is at least legible 😂. About the If you have suggestions regarding that, please do let me know. |
Ok I see. Another option, although a bit verbose, would be to use arrays to group key/value pairs. eg. |
src/std/2-std-lang.md
Outdated
|
||
The **lang** module offers a way to create user-defined structures and enumerations. | ||
|
||
A structure can pack together variables and functions, which allow object-oriented programming. |
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.
allows
src/std/2-std-lang.md
Outdated
``` | ||
lang.struct(field = value, ...) -> type | ||
``` | ||
Creates a new structure type type holding a set of `field`s. The given `value`s are used to infer the type of each field and as default values during construction. The return type can be used to instantiate objects of this type. |
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.
returned
src/std/2-std-lang.md
Outdated
``` | ||
Creates a new structure type type holding a set of `field`s. The given `value`s are used to infer the type of each field and as default values during construction. The return type can be used to instantiate objects of this type. | ||
|
||
Adding member functions to a type is done with the `let func in type = fn(args) {}` construct, with `func` being the function's name. Inside the function, variables and functions belonging to the type can be accessed using the `self` keyword. |
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.
semicolon after {}
src/std/3-std-strings.md
Outdated
The **str** module defines member functions for the native `string` type and other string manipulation related functions. | ||
The functions available natively in the language can be consulted [here](/13-core-functions.html#string). | ||
|
||
A `string` is a sequence of characters. There is no character type in **Feral** and so are represented are one character strings. |
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.
so are represented as
src/std/4-std-vectors.md
Outdated
``` | ||
vector.slice(start: int, end: int = -1) -> vector | ||
``` | ||
Extracts the elements from `start` to `end - 1` and returns them in a new vector. If `end == -1` then the slice ends at the end of the vector |
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.
you may wanna add:
any modification in the elements of a slice will affect its original vector as well
src/std/5-std-maps.md
Outdated
@@ -0,0 +1,177 @@ | |||
# Maps | |||
|
|||
The **map** module defines the `map` type and all the vector manipulation related functions. |
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.
vector map
src/std/5-std-maps.md
Outdated
{Answer?: 42, 0: Zero, 1: One} | ||
``` | ||
|
||
Note that the elements are not stored in the order they are given. They are lexicographically sorted |
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.
They are not sorted at all - c++'s unordered_map
.
From cppreference's unordered_map
page:
Internally, the elements are not sorted in any particular order, but organized into buckets. Which bucket an element is placed into depends entirely on the hash of its key. This allows fast access to individual elements, since once the hash is computed, it refers to the exact bucket the element is placed into.
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.
Oops, I was probably thinking of std::map
when I wrote this
Just read it. Added some comments. |
Thanks for the comments, I'll address them |
@@ -122,6 +122,6 @@ io.println(hello[5]); | |||
|
|||
Output: | |||
``` | |||
h | |||
! | |||
(nil) |
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.
umm... (nil)
should have been !
and h
should be as it is 😛
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.
🤦
src/std/5-std-maps.md
Outdated
@@ -40,7 +40,7 @@ Gives the output: | |||
{Answer?: 42, 0: Zero, 1: One} | |||
``` | |||
|
|||
Note that the elements are not stored in the order they are given. They are lexicographically sorted | |||
Note that the elements are not stored in any particular order and thus does not necessarily follow the given one |
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.
thus does not thus do not
src/std/10-std-builder.md
Outdated
@@ -1 +1,175 @@ | |||
# Builder | |||
|
|||
The **builder** module defines a `builder` type that allows to build and install C++ modules to be used with Feral |
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.
builder_t
type
install C++ modules install external modules
(because it's not C++ exclusive, it can install Feral only modules too)
src/std/10-std-builder.md
Outdated
|
||
The **builder** module defines a `builder` type that allows to build and install C++ modules to be used with Feral | ||
|
||
A guide on how to write and build modules for Feral can be read [here](https://levelup.gitconnected.com/writing-c-modules-for-feral-391c30ac7739). |
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.
please use this URL:
https://medium.com/p/writing-c-modules-for-feral-391c30ac7739?source=email-852839018f8a--writer.postDistributed&sk=b2de39e5f849e75e3b4ea9bdeeb1b4db
it does not require medium membership
src/std/10-std-builder.md
Outdated
|
||
### new | ||
``` | ||
builder.new() -> builder |
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.
-> builder -> builder_t
src/std/10-std-builder.md
Outdated
|
||
Possible output: | ||
``` | ||
typeid<14>{linker_flags: , lib_flags: -lferalvm -lgmpxx -lgmp -lmpfr , lib_dirs: -L/usr/lib -L/usr/local/lib/feral , srcs: , ccache: /usr/bin/ccache , compiler: g++, is_dll: false, compiler_opts: -std=c++11 -O2 , inc_dirs: -I/usr/include } |
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.
in commit 50217df of Feral-Std, added typename for builder_t so now it will show builder_t
instead of typeid<14>
src/std/10-std-builder.md
Outdated
|
||
### make_dll | ||
``` | ||
builder.make_dll() -> builder |
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.
-> builder -> builder_t
src/std/10-std-builder.md
Outdated
|
||
### add_comp_opts | ||
``` | ||
builder.add_comp_opts(opt: string) -> builder |
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.
-> builder -> builder_t
src/std/10-std-builder.md
Outdated
|
||
### add_inc | ||
``` | ||
builder.add_inc(inc_dir: string) -> builder |
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.
-> builder -> builder_t
src/std/10-std-builder.md
Outdated
|
||
### add_lib | ||
``` | ||
builder.add_lib(lib_flag : string, lib_dir = '' : string) -> builder |
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.
-> builder -> builder_t
src/std/10-std-builder.md
Outdated
|
||
### add_src | ||
``` | ||
builder.add_src(src: string) -> builder |
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.
-> builder -> builder_t
src/std/10-std-builder.md
Outdated
|
||
### perform | ||
``` | ||
builder.perform(output_file: string, .kw_args) -> builder |
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.
returns integer, not builder_t
(0 = success, fail otherwise)
src/std/10-std-builder.md
Outdated
@@ -24,7 +24,7 @@ let sys = import('std/sys'); | |||
|
|||
### new | |||
``` | |||
builder.new() -> builder | |||
builder.new() -> builder_t_t |
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.
_t_t
😂
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.
🤦♂️ Damn, seems I didn't turn on the 'whole word' option when doing the search and replace...
So awesome work!! Thanks a lot! ❤️ |
okay merged and built. It's available now 😁 |
Creating a PR now so that I can get early feedback.
So far, I just created the pages listed in Feral-Lang/Feral#8. I'll start enumerating what's available in each module and then we can see what's the best way to organize it