Erlang Erros on Compile a tiny program (doubs about erlang ponctuation).

Hi folks. I’m attempt to compile a tiny project, yet on it’s scaffolding, and I’m getting some errors.

Blockquote
lukas@lukas-ThinkPad-T460 ~/D/d/erlang [1]> mv fib.erl scf.erl
lukas@lukas-ThinkPad-T460 ~/D/d/erlang> erlc -pa . -Dname scf.erl -noshell -noinput
scf.erl:16:5: syntax error before: ‘end’
% 16| end.
% | ^

scf.erl:21:5: syntax error before: while
% 21| while(content =:= cached[index][“content”]) →
% | ^

scf.erl:2:2: function get/1 undefined
% 2| -export([get/1, locate/2]).
% | ^

scf.erl:2:2: function locate/2 undefined
% 2| -export([get/1, locate/2]).
% | ^

The code goes here: Pastebin

The line numbers are wrong and some of the code is missing but here are reasons for errors

You have a ; before the end of the try. The ; is NEVER a terminator, it is ALWAYS a separator.

This bit is missing but Erlang doesn’t have `while construct.

Seeing there are errors in the functions then neither function has been defined and so they don’t exist and you therefore can’t export them.

1 Like

The functions missing I noted before that the question was posted.

On the try block I can’t understand what are the punctuation to be used.
If you could post example on this (have a pastebin attached to the question) I will be glad and will fully comprehend. An example of the how should be this part of the code.

On the while block, I suppose that is the erlang 27.1. I saw on the net I want to test.

Thanks, Lukas.

Please just post your code. The Pastebin you linked to doesn’t match the compilation errors you quoted at all, so there is nothing anyone can reasonably comment on.

1 Like

Can you paste an example using the pastebin the I create on how should be the program? Still getting error.s

Robert Virding already explained.
SEMICOLON IS ALWAYS A SEPARATOR NEVER A TERMINATOR.
You should start by reading (and I hope it is REreading)
https://www.erlang.org/doc/reference_manual/expressions
in particular section “9.22 try”.
Putting Erlang tokens between single quotes, the syntax is
‘try’ Expr (‘,’ Expr)* ‘catch’ Handler (‘;’ Handler)* ‘end’.
Just as ‘,’ goes between Exprs, so ‘;’ goes between Handlers.

Judging from the pastebin, you may be trying to learn Erlang from a large language
model ‘AI’. I have seen a lot of complete garbage coming from ChatGPT, in several
programming languages. It’s not worth it. Examples in RosettaCode.org are a
better idea, but not as good as a good book.
Or a good web site: https://learnyousomeerlang.com/

3 Likes

What program? The pastebin you linked to contains a meaningless jumble of tokens.
If I recall correctly, for example, it uses “length(etag)” at some point. But
etag is an atom and doesn’t have a length.

While Erlang has an exception-handling system, it’s an advanced topic.
Deliberately programmed long-range transfers of control using erlang:throw/1
are one thing, exceptions are quite another, and given my druthers I’d have
preferred throws and exceptions to be handled by different mechanisms.
Ever since I first met exceptions in PL/I longer ago than I care to admit, I
have been baffled by the idea of recovering from exceptions. I’ve been working
on a Smalltalk compiler for years. I’m not trying to convert every kind of error
report (initially using the traditional #error: selector) to use ANSI exception
handling, and having to figure out what the exceptions should be, because the
people who wrote the ANSI standard forgot to say. And it has been driven home
to me that the ANSI Smalltalk exception facility’s ability to say “Hey, I’ve fixed
it, try again!” is a complete waste of time, because classifying exceptions by
their symptom doesn’t help a program figure out what to do about it. And
Erlang exceptions have the same problem. Reporting, for example, that there
was a division by zero doesn’t tell you why there was a division by zero, or
what you can do about it.

Once you have mastered ‘case’, the syntax of ‘try’ will be very nearly obvious.
And you will use ‘case’ far far more often than ‘try’.

3 Likes