0

In the following sections of code I am receiving errors that I am not sure why I am getting them despite using all of my resources to research them. This is SMLNJ coding.

compComm (DeallocComm(var, exp), env, ip, codes, contIP)=
 let val loc = lookupEnv var env;
  val codes1 = emitByte(LDC, ip, codes);
  val codes2 = emitByte(Arg loc, ip + 1, codes1);
  val (ip', codes3) = compExp(exp, env, ip+2, codes2);
  val codes4 = emitByte(ADEALLOC, ip', codes3);
   in(ip'+1, codes4, nil, contIP)
  end;

gives

hw4.sml:339.5-433.6 Error: non-constructor applied to argument in pattern: DeallocComm hw4.sml:427.26-427.29 Error: unbound variable or constructor: var

hw4.sml:430.31-430.34 Error: unbound variable or constructor: exp

and

ADEALLOC => let val (n, stack') = popStack stack
 val (loc, stack'') = popStack stack';
 fun loop'(n, loc, store) =
  val store' = updateTable (loc, defaultIntValue, store);
  in loop'(n-1, loc+1, store) =
   val store'' = loop'(n, loc, store) end;
 in loop(ip+1, store'', stack'') end;

gives

hw4.sml:612.14 Error: syntax error: inserting EQUALOP

hw4.sml:615.8-615.11 Error: syntax error: replacing VAL with END

any help on these would be appreciated.

2 Answers 2

1

You can call a function as an argument to be passed to another function, but you're doing so incorrectly. The correct syntax is to call the function name with no arguments or perentheses, then to use the function passed as an argument within the body of the function to which it is passed.

So you would want your function declaration to be:

compComm (DeallocComm, env, ip, codes, contIP)=

and then use DeallocComm in the body. As it stands, you're creating an environment variable which has a value but no name -- DeallocComm(var, exp) evaluates before being passed into the function.

Sign up to request clarification or add additional context in comments.

1 Comment

@Crowbreak, try to give more directive advice to the user,
0

So for the first one, I think it can't find the constructor DeallocComm. (Where is that declared from?)

For the second one, it makes no sense. I have no idea what you are doing. Are store' and store'' inside the loop' function or outside that function? If the former, then why isn't it inside a let? If the latter, where is the body of loop'; and how can you use store'' in the expression in the end, which is outside the function? Also, there is no value called loop. It seems that you are missing lots of fun, let, and other things.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.