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

  • Home
  • SEARCH
  • 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 8549059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:38:19+00:00 2026-06-11T13:38:19+00:00

fun temp(x) = let val a = x in if a mod (x-1) =

  • 0
fun temp(x) = 
let val a = x
in if a mod (x-1) = 0 then x
   else temp(x-1)
end;

this is example Standard ML code.

What I want to know is that
for example user call temp(10); then a = 10 and the temp(x-1) is called.

then the variable ‘a’ will change to 9. Can I keep it as 10 in Standard ML?

  • 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-06-11T13:38:21+00:00Added an answer on June 11, 2026 at 1:38 pm

    If your function contains val a = x, then for any invocation of temp(x), the value of a will be equal to the value of x. If you want to remember the value of a from a previous invocation when you recurse, you need to pass it around as a parameter like this:

    fun temp_helper x a =
      if a mod (x-1) = 0 then x
      else temp_helper (x-1)
    
    fun temp x = temp_helper x x
    

    You could also make the helper function an inner function. If you do that, you can actually remove a as a parameter and instead close over a like this:

    fun temp x =
    let
      val a = x
      fun helper x =
        if a mod (x-1) = 0 then x
        else helper (x-1)
    in
      helper x
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function fun that returns a double. I want to call the
I write some code to learning F#. Here is a example: let nextPrime list=
Say I have a recursive function that I want to know how many times
Script: $aString = "This is Just a temp string just for fun"; print '^^^^^^^^'
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
Working through this for fun: http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/ Example calculation of nullable and first uses a
I'm having a fun issue, I have LiveReload working in Chrome, so I know
Just for fun, I wrote this simple function to reverse a string in Python:
I am having fun creating my own wallpaper changer program. I know there are
I have some fun with unicode text sources (all correct encodet) and I want

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.