zackradisic / aussieplusplus

Programming language from down under
aussieplusplus.vercel.app
610 stars 15 forks source link

Importing modules #3

Open jwfxpr opened 2 years ago

jwfxpr commented 2 years ago

As well as importing built-in functions with IMPOHT ME FUNC, a keyword for importing user-defined modules should be defined. I suggest OI, or COOEE.

E.g.

IMPOHT ME FUNC ChuckSomeDice;
COOEE utilities.aussie;
IMPOHT ME FUNC HitTheSack;
OI gizzabeerdahl.aussie;
jwfxpr commented 2 years ago

Or if you think those keywords are best reserved for other uses, CAAARN would also work well.

iancwwong commented 2 years ago

How about WELCOME LAD?

bbrk24 commented 2 years ago

How does the module declare what it exports vs what it doesn't? Would it use...

zackradisic commented 2 years ago

Haha great ideas @jwfxpr, though I do think OI and COOEE might have better uses.

@bbrk24 Brought up some good points.

For imports/exports, I think JavaScript's ES6 syntax is simple and intuitive:

// main.aussie
IMPOHT < meFunc, meVar > FROM ME MODULE "./module"

Though I think the syntax is too close to ES6, so I would need help making it more 'Strayan.

I have no idea how to represent exports in strayan lingo, here's an idea:

I RECKON x = 5;
I RECKON y = 6;

I RECKON I'LL SHOW OFF < x, y >;

With this system I think we should do away with IMPOHT ME FUNC <func> for built-ins and instead have a stdlib module:

// Import only what you need
IMPOHT < HitTheSack, ChuckSomeDice > FROM ME MODULE "std"

// Can also do this:
IMPORT std FROM ME MODULE "std"

std.ChuckSomeDice(0, 420);
jwfxpr commented 2 years ago

Here's a 'strayafication option for the importing syntax:

HAVE A GO AT < HitTheSack, ChuckSomeDice > FROM "std" YA MUG
HAVE A GO AT std FROM "std" YA MUG
bbrk24 commented 2 years ago
// Import only what you need
IMPOHT < HitTheSack, ChuckSomeDice > FROM ME MODULE "std"

// Can also do this:
IMPORT std FROM ME MODULE "std"

std.ChuckSomeDice(0, 420);

I agree that this looks a bit too much like JS, even hinting at object destructuring -- something I rarely see elsewhere. As far as I'm aware, doing this in ES6:

import { HitTheSack, ChuckSomeDice } from 'std';

Is just a syntactical sugar for something along the lines of:

import * as std from 'std';
const { HitTheSack, ChuckSomeDice } = std;

In Swift, this destructuring is automatic unless shadowed:

import std

func HitTheSack(_ t: Int) {
}

// automatically resolves to std.ChuckSomeDice(_:_:)
ChuckSomeDice(0, 10)

// resolves to user-defined function
HitTheSack(1000)

// resolves to the specifically imported one
std.HitTheSack(1000)

Personally, I'm partial to the way Swift does it.

Edit: I'm taking this way too seriously aren't I

zackradisic commented 2 years ago

In this case I prefer the imports to be explicit/declarative, because then it's easier to tell where the imports are coming from, especially since we are a long way from having jump-to-definition and other utilities that make the Swift way manageable.

I'd still to like to hear if anyone has any ideas for making the syntax look less like ES6, I also like Rust's syntax for importing:

use std::{ffi::CString, mem, os::raw::c_char};

Maybe something like this:

IMPOHT ME MODULE std
IMPOHT ME MODULE std AND TAKE <ChuckSomeDice, HitTheSack>