# Standard ML (Moscow) question.

**URL:** <https://boards.straightdope.com/t/standard-ml-moscow-question/324020>\
**Category:** Factual Questions\
**Created:** [September 29, 2005, 2:26pm UTC](https://boards.straightdope.com/t/standard-ml-moscow-question/324020 "2005-09-29T14:26:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Capt.Ridley\_s\_Shooting\_Party](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Capt.Ridley\_s\_Shooting\_Party](https://boards.straightdope.com/u/Capt.Ridley_s_Shooting_Party)\
**Post date:** [September 29, 2005, 2:26pm UTC](https://boards.straightdope.com/t/standard-ml-moscow-question/324020/1 "2005-09-29T14:26:47Z")

</div>

I’ve elected to take a course in functional programming that uses SML (Moscow ML). So far, we’ve mostly been using the interactive top level, but now I need to write an assignment in an .sml file for submission.

The problem is, whenever I write a val statement, and load my file into the interpreter, it baulks. For instance, this is my file:

```auto

fun soundex name =
	val list = String.explode name;
	val firstCharacter = List.nth (list, 0);
	val listWithoutFirst = List.drop (list, 1);

```

Loading that into mosml using use “soundex.sml” produces the following error:

```auto

[opening file "soundex.sml"]
File "soundex.sml", line 2, characters 1-4:
! val list = String.explode name;
! ^^^
! Syntax error.
[closing file "soundex.sml"]

```

What am I doing wrong? Using the same val statements in the top level (without the function surrounding them) works fine.

Thanks.

---

<div class="post-metadata">

**Author:** ![Bytegeist](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bytegeist](https://boards.straightdope.com/u/Bytegeist)\
**Post date:** [September 29, 2005, 2:48pm UTC](https://boards.straightdope.com/t/standard-ml-moscow-question/324020/2 "2005-09-29T14:48:37Z")

</div>

Two things to try: (1) I don’t think you want those semi-colons in any code meant for compilation (only in the interactive interpreter), and (2) although the compiler didn’t complain about it yet, your function doesn’t compute anything. I think you want:

```auto

fun soundex name =
  let
    val list = String.explode name
    val firstCharacter = List.nth (list, 0)
    val listWithoutFirst = List.drop (list, 1)
  in
    [Compute or do something here.]
  end

```

I haven’t tested this however.

---

<div class="post-metadata">

**Author:** ![Capt.Ridley\_s\_Shooting\_Party](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Capt.Ridley\_s\_Shooting\_Party](https://boards.straightdope.com/u/Capt.Ridley_s_Shooting_Party)\
**Post date:** [September 29, 2005, 4:10pm UTC](https://boards.straightdope.com/t/standard-ml-moscow-question/324020/3 "2005-09-29T16:10:25Z")

</div>

Belting. Worked great, thanks.
