-
Notifications
You must be signed in to change notification settings - Fork 21
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
Style guide for std.<language>? #23
Comments
Writing a document on implementing the standard library is a great idea. I have plans to start writing one within the next day or two. Until then, you could look at this example if you want to see how to use foreign functions not provided by the |
I could implement printing to an HTML element as an external library, but my concern is that that would make code written for the TypeScript target incompatible with other targets, and code written for other targets much less useful when built with the TypeScript target. |
An external library would probably be the way to do it. Then, you can use an Oak file with conditional compilation to guard against using the function without the TS backend. |
That would fix the first problem, but the second problem still stands. To get output displayed on the page for any Oak program not written specifically for the TS target, one would either have to
None of these are particularly desirable solutions One possible solution would be an option to mark a target as |
Hm, i don't fully understand the problems here. All the stdlib spec has to do is define a function that allows the programmer to print to stdout. Your standard library then implements this by appending the output to an HTMLElement right? |
That's my current implementation, and it works pretty well so far. My original request was for a standard way of naming variables/functions in |
Hm, how would that limit portability? I think it all depends on what the program intention is. If i write a program and stdlib spec says that For example lets assume the oak stdlib has the following function: fn print(str: &char) -> void; An oak program uses that function as followed: fn main() {
print("hello world!");
} Then it is up to your implementation to define what stdout is and implement the // implementation detail
function print(str: string) {
console.log(str);
}
// implementation detail
function print(str: string) {
const el = document.querySelector('#console');
el.innerHTML += str;
} Tough if the Oak program specificly wants to write to an HTMLElement than an external function that implements an interface for this would be more appropiate. |
Whoops, didn't mean to close this. I guess it does make sense to just choose one or the other as stdout. Thanks for the feedback! |
A style guide for implementing the standard library would be helpful, especially specifying a way to make variables and functions that are not currently in
std.c
orstd.go
.For example, I'm working on a TypeScript backend right now. One thing I'm working on implementing is the ability to choose between printing with
console.log
or printing to an HTML element. Right now I've implemented this by putting these lines at the top ofstd.ts
I guess this is also my proposal for naming these functions/variables.
OAK_<file extension of the language>__<name of function or variable>
The text was updated successfully, but these errors were encountered: