#Creating Modules & Project Structure

1 messages · Page 1 of 1 (latest)

torn trellis
#

I was looking through the Gleam docs and it mentions modules, but not much about creating your own modules. I'm looking to create a module for myself so that I can encapsulate some code and write specific unit tests for that code. My first attempt looks something like this:

fancy/ (root)
  compiler/
  lib/
    lexer/
      lexer.gleam
  src/
    compiler.gleam

The problem is that I can't quite call my module from the compiler.gleam file. So i'm wondering if modules should all live in the src directory or if there's a convention to also have something like a lib (I believe Rust does a src and lib?)

errant locust
#

its all src

torn trellis
#

Gotcha 👍

tiny carbon
#

Rust does just src btw

torn trellis
#

I thought Rust had lib? maybe within src? My memory clearly evades me lo

tiny carbon
#

Nah

#

There's a lib.rs file you can make if you want

errant locust
torn trellis
#

I was actally thinking of that meme lol

#

Just to follow up and I can close this off:

fancy/ (root)
  compiler/
  src/
    compiler.gleam
    lexer.gleam

This works, and I can import the lexer into my compiler like import lexer 👍

cosmic canyon
#

if you're making a package, it's recommended to have a folder under src to namespace your modules (except maybe the main module) to avoid name clashes, because the module namespace is global

tiny carbon
#

You're polluting the global namespace there!