Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6013365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:32:16+00:00 2026-05-23T02:32:16+00:00

I’m a newby. I write below code. Delay(e) == fn () => e Force(e)

  • 0

I’m a newby. I write below code.

Delay(e) == fn () => e
Force(e) == e()

fun time_consuming(n) =
   let fun tak(x, y, z) = if x <= y then y
               else tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y))
   in          
fun   tak(3*n, 2*n, n)
funend;
fun fib(n) = if n=0 orelse n=1 then 1 else fib(n-1) + fib(n-2);
fun odd(n) = (n mod 2) = 1;
fun f(x, y) = if odd(x) then 1 else fib(y);
f(fib(9), time_consuming(9));

fun lazy_f(x, y) = if odd(x) then 1 else fib(y());
lazy_f(fib(9), fn () => (time_consuming(9)));

It is lazy evaluation code.
But it has some error.

lazy.sml:1.13 Error: syntax error: inserting LPAREN
lazy.sml:4.2 Error: syntax error: inserting LET
lazy.sml:12.44 Error: syntax error: replacing SEMICOLON with EQUALOP
lazy.sml:15.21 Error: syntax error: inserting LPAREN
lazy.sml:17.1 Error: syntax error found at EOF

What these error mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:32:17+00:00Added an answer on May 23, 2026 at 2:32 am

    In SML, errors will often cascade, that is, one fault can cause the loads of errors after the location of the fault. Therefore, a good tactic is to only look at the very first error, correct it, and retry the code.

    If we look at your first error:

    lazy.sml:1.13 Error: syntax error: inserting LPAREN
    

    , we can see that it is caused by the first line. If we look at it, this is how it is interpreted by sml; Take the function Delay, send e as argument and get a new function as result. Take this function and send == as argument and get yet another function, to which the lambda function fn () => e is passed. However, SML syntax dictates that in order to pass lambda functions as arguments, they must be surrounded by parantheses, so it issues the error for missing left parantheses, which is cryptically written as “inserting LPAREN”.

    However, I do not see what the purpose of the first two lines, since the rest of the code is independent of it, and almost correct in syntax too, so now I will simply comment them out (surround them with “(*” and “*)”.

    Lets run the new code and look at the first of the new errors:

    lazy.sml:7.4-8.4 Error: syntax error: deleting  IN FUN
    

    Now we turn our attention to the eighth line, and see that it and the ninth has by mistake been prefixed with “fun”. We replace the “fun” on line eight and nine with spaces and run it again.

    Now it works! This is the working code:

    (* Delay(e) == fn () => e *)
    (* Force(e) == e() *)
    
    fun time_consuming(n) =
       let fun tak(x, y, z) = if x <= y then y
                   else tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y))
       in          
          tak(3*n, 2*n, n)
       end;
    fun fib(n) = if n=0 orelse n=1 then 1 else fib(n-1) + fib(n-2);
    fun odd(n) = (n mod 2) = 1;
    fun f(x, y) = if odd(x) then 1 else fib(y);
    f(fib(9), time_consuming(9));
    
    fun lazy_f(x, y) = if odd(x) then 1 else fib(y());
    lazy_f(fib(9), fn () => (time_consuming(9)));
    

    As you could see, there were more errors than mistakes, and I hope that you have learnt that decoding the meaning of the error messages is not necessary, and simply looking at the location of the first error is often enough to realize what is wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.