Akuli / jou

Yet another programming language
MIT License
12 stars 4 forks source link

A way to mark symbols as private #84

Open Akuli opened 1 year ago

Akuli commented 1 year ago

Currently all functions and structs are made available for other files to import. There should be a way to make functions and structs be visible only within the current file.

Maybe static?

static def internal_util_function() -> int:
    return 123

static struct PrivateStruct:
    x: int
    y: int

def public_function() -> int:
    return internal_util_function() * 2

struct PublicStruct:
    message: byte*
    line: int
littlewhitecloud commented 1 year ago

I think on the contrary, you can use the "extern" keyword to decide which functions need to be exported. Then other variables, functions, structs of the current file will not be accessed.And then, they will be private

littlewhitecloud commented 1 year ago
def internal_util_function() -> int:
    return 123

static struct PrivateStruct:
    x: int
    y: int

extern def public_function() -> int:
    return internal_util_function() * 2

extern struct PublicStruct:
    message: byte*
    line: int
Akuli commented 1 year ago

I think on the contrary, you can use the "extern" keyword to decide which functions need to be exported. Then other variables, functions, structs of the current file will not be accessed.And then, they will be private

So basically, everything is private by default, and you can use a keyword like extern to make public things. This seems like a good idea.

I think I will probably name the keyword public instead of extern, for two reasons:

Akuli commented 1 year ago

More possible keywords to use for this:

Akuli commented 1 year ago
sumeshir26 commented 1 year ago

I think global or public will be the most clear

Moosems commented 11 months ago

public looks fine to me. I understood extern just fine and would be a little disappointed if someone couldn't deduce its meaning.

Akuli commented 11 months ago

It seems that everyone is happy with public. I will use it when I eventually get around to implementing this :)

Akuli commented 11 months ago

How about a decorator?

@public
def add(x: int, y: int) -> int:
    return x + y
Moosems commented 11 months ago

I like that, but if it isn't written in Jou that would feel a bit too automagic-y for a decorator.