Skip to content
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

how do I import functions? #22

Open
richardanaya opened this issue Mar 25, 2019 · 1 comment
Open

how do I import functions? #22

richardanaya opened this issue Mar 25, 2019 · 1 comment

Comments

@richardanaya
Copy link

No description provided.

@menduz
Copy link
Member

menduz commented Mar 25, 2019

you can reference functions by its module and name using fully qualified names

fun main(): void = {
  support::env::printf("number is %d", 1)
}

Or you can import the whole module and the names will be available locally

import support::env

fun main(): void = {
  printf("number is %d", 1)
}

The fully::qualified::names represent the path of the module starting at the root of the project / standard library.

So if you have a structure like:

// lib/folder/file.lys

struct NumberWrapper(number: i32)

fun add(a: NumberWrapper, b: NumberWrapper): NumberWrapper = 
  NumberWrapper(a.number + b.number)
// lib/main.lys
import lib::folder::file
fun main(): i32 = add(NumberWrapper(1), NumberWrapper(2))

which is the same as

fun main(): i32 = 
  lib::folder::file::add(
    lib::folder::file::NumberWrapper(1),
    lib::folder::file::NumberWrapper(2)
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants