Gleam: Running an App

Created on 18 Apr 2020  路  7Comments  路  Source: gleam-lang/gleam

Hey there, love the project! Forgive me for asking a silly question.

I followed the Getting Started docs, installing with brew install gleam and then running gleam new app --template app --description "First". I then did cd app and rebar3 compile and I get a _build output directory. How, then, do I run the app?

(I also tried rebar3 shell and got the REPL, tried let a = hello_world() (hello_world being the default function defined in the scaffolded project) but no response. In fact, nothing I type seems to have any effect at all! Not sure what I'm missing.)

Thanks!

Most helpful comment

Since you've never used Erlang before, this is the best introduction to the shell: lyse. @tooolbox

All 7 comments

Hello @tooolbox I'm fairly new to Gleam but I always use gleam build followed by rebar3 shell.

You will need to execute your function from the appropiate module (which is your filename) so for example if my file is named src/start.gleam the function you want is at:

start:hello_word().

Thanks for the reply @chouzar

Good to know on gleam build, perhaps that should be added to https://gleam.run/getting-started/creating-a-project.html as it essentially points you at the rebar3 docs, which say to use rebar3 compile. It's a little unclear to me how those two things interact, I guess gleam build calls rebar3 compile when it's done with its pass?

When I run rebar3 shell I do get a sort of "prompt" but it does nothing at all. It seems that no text I can enter will produce any sort of output: no evaluation, no error message.

For comparison, I tried cloning out https://github.com/gleam-lang/example-url-shortener and doing rebar3 shell as it says. This is the output:

~/g/example-url-shortener> rebar3 shell
===> Verifying dependencies...
Compiling gleam/order
Compiling gleam/result
Compiling gleam/iodata
Compiling tiny/html
Compiling gleam/pair
Compiling gleam/float
Compiling gleam/expect
Compiling gleam/bool
Compiling gleam/atom
Compiling gleam/int
Compiling gleam/list
Compiling gleam/map
Compiling gleam/dynamic
Compiling gleam/string
Compiling gleam/http
Compiling gleam/otp/process
Compiling gleam/elli
Compiling gleam/otp/basic_supervisor
Compiling gleam/otp/stop
Compiling gleam/otp/agent
Compiling tiny/db
Compiling tiny/web
Compiling tiny/supervisor
Done!
===> Compiling tiny
Erlang/OTP 22 [erts-10.7.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]

Eshell V10.7.1  (abort with ^G)
1> ===> The rebar3 shell is a development tool; to deploy applications in production, consider using releases (http://www.rebar3.org/docs/releases)
===> Booted tiny

The http server starts! (A little notice like "listening on port 3000" would be nice, but I figured out the port from reading web.gleam.)

But, the shell doesn't do anything no matter what I enter. I suppose it's not meant to be a REPL? I even tried the rebar3 commands from the documentation and no dice.

Also, when I ctrl^c to exit, it somehow glitches my shell by injecting crazy indentation into stdout; possibly I'm not shutting it down correctly, but having to reboot my shell is annoying.

I'm sure this is all due to my inexperience with the Erlang ecosystem and the newness of Gleam, so I do apologize, but maybe this is good info for onboarding new people.

Also, when I ctrl^c to exit, it somehow glitches my shell by injecting crazy indentation into stdout; possibly I'm not shutting it down correctly, but having to reboot my shell is annoying.

That doesn't sound like normal behaviour from the rebar3 shell command, on my machine it looks quite clean. Your version of erlang and eshell seem to be up to date :thinking:

Good to know on gleam build, perhaps that should be added to https://gleam.run/getting-started/creating-a-project.html

As far as I know the docs are being worked on! :smile:

I'm sure this is all due to my inexperience with the Erlang ecosystem and the newness of Gleam, so I do apologize, but maybe this is good info for onboarding new people.

No worries! I come from an elixir background (even though I would really love to go deeper into erlang). While more involved something we could try is the erlang shell instead of rebar (not sure if these tools are actually any different).

In your project's root try gleam build which should generate erlang files at the gen/src directory. Then type erl to open the erlang shell and load your generated erlang module with:

your_shell$ build gleam
your_shell$ erl
Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Eshell V10.4.4  (abort with ^G)
1> c("gen/src/hello.erl").
{ok, hello}
2> hello:world().
"hello world!"

Hi! Thanks for trying Gleam!

We're using rebar3, so we use the releases feature to run our code. More info can be found here: https://www.rebar3.org/docs/releases.
Typically we use unit tests to or the rebar3 shell to run our code in dev.

(I also tried rebar3 shell and got the REPL, tried let a = hello_world() (hello_world being the default function defined in the scaffolded project) but no response. In fact, nothing I type seems to have any effect at all! Not sure what I'm missing.)

The shell is an Erlang REPL, not a Gleam one, so you'll need to use Erlang syntax there. The most common problem is forgetting to enter a ., which is like a ; in C etc.

Also, when I ctrl^c to exit, it somehow glitches my shell by injecting crazy indentation into stdout; possibly I'm not shutting it down correctly, but having to reboot my shell is annoying.

opens a menu in the Erlang shell, if you wish to exit you'll want to press it twice.

The http server starts! (A little notice like "listening on port 3000" would be nice, but I figured out the port from reading web.gleam.)

Yes! We will add this and more soon. The example project is currently little more than a rough sketch and could be greatly improved.

Many things about the Erlang build tools can be confusing to new users for sure. We will work to improve this experience at a later date, but for now we are focusing on implementing the core language itself and users will have to become familiar with Erlang build tooling.

I like your idea of adding more information to the project creation documentation! That will be very useful.

Thanks @chouzar for helping here 馃挏

The shell is an Erlang REPL, not a Gleam one, so you'll need to use Erlang syntax there. The most common problem is forgetting to enter a ., which is like a ; in C etc.

Ah, that was the problem. Using . does run my commands, thanks.

opens a menu in the Erlang shell, if you wish to exit you'll want to press it twice.

Pressing it twice does eject me from the shell, but the crazy indentation thing still happens. I'm running zsh with the fishy theme on a 2017 MBP, Catalina. Not pressing, but an odd issue.

Thanks for the awesome project!

Since you've never used Erlang before, this is the best introduction to the shell: lyse. @tooolbox

That is strange @tooolbox . It might be worth asking in the Erlang IRC channel or in the rebar3 issue tracker about any problems you are having with it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lpil picture lpil  路  7Comments

lpil picture lpil  路  3Comments

michaeljones picture michaeljones  路  6Comments

lpil picture lpil  路  7Comments

lpil picture lpil  路  7Comments