# Same code doesnt work with ocamlc vs online editor

**URL:** <https://discuss.ocaml.org/t/same-code-doesnt-work-with-ocamlc-vs-online-editor/15817>\
**Category:** Learning\
**Tags:** compilation\
**Created:** [December 20, 2024, 12:24am UTC](https://discuss.ocaml.org/t/same-code-doesnt-work-with-ocamlc-vs-online-editor/15817 "2024-12-20T00:24:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![satyajit\_sarangdhar](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/satyajit_sarangdhar/32/5666_2.png) [@satyajit\_sarangdhar](https://discuss.ocaml.org/u/satyajit_sarangdhar)\
**Post date:** [December 20, 2024, 12:24am UTC](https://discuss.ocaml.org/t/same-code-doesnt-work-with-ocamlc-vs-online-editor/15817/1 "2024-12-20T00:24:03Z")

</div>

```auto
type 'a stack = 'a list ref

let create () = ref []

let add stack x = stack := x::!stack

let pop stack =
  match !stack with
    [] -> raise (Invalid_argument "pop")
   |x::xs -> stack := xs;
             x

let size_of stack =
  List.length !stack

let my_stack = create ()

let _ = add my_stack 3;

let popped = pop my_stack in Printf.printf "%d\n" popped
 

```

When I try to compile this

```auto
 ocamlc Stack.ml -o Stack

File "Stack.ml", line 20, characters 26-28:

20 | let popped = pop my_stack in Printf.printf "%d\n" popped;
                                                  ^^
Error: Syntax error

```

This same code works in TryOcaml online editor.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [December 20, 2024, 8:13am UTC](https://discuss.ocaml.org/t/same-code-doesnt-work-with-ocamlc-vs-online-editor/15817/2 "2024-12-20T08:13:38Z")

</div>

> [@satyajit\_sarangdhar](#):
>
> ```auto
> let _ = add my_stack 3;
> 
> ```

The trailing `;` is the source of the syntax error, it makes the rest of your code reads as

```ocaml
let _ =
  add my_stack 3;
  let popped = pop my_stack in Printf.printf "%d\n" popped

```

The playground toplevel is then discarding this last incomplete sentence because you may complete it later whereas `ocamlc` has to fail on the incomplete sentence.
