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 6571283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:51:44+00:00 2026-05-25T14:51:44+00:00

A couple of my friends are working on a simple recursive function in SML,

  • 0

A couple of my friends are working on a simple recursive function in SML, and so far have failed to create it due to a lack of documentation of SML and its syntax. I’ve tried to find something myself in order to help them, but have been unsuccessful so far.

Here’s the function I made in Java. It works and I’d like to convert the concept of this function into SML.

 private static int shift;
 private static boolean firstRun = true;

 private static void crackThatThing(int clearText, int cryptoText) {
  if (firstRun) { // Make sure that the shift is only set once
   firstRun = false;
   shift = ((cryptoText % 10) - (clearText % 10)) % 10;
   crackThatThing((clearText / 10), (cryptoText / 10));
  } else {
   if (clearText > 0 && cryptoText > 0) {
    if (shift != ((cryptoText % 10) - (clearText % 10)) % 10) {
     // The shift value changed - this is not a valid encryption!
     System.out.println("This is not a valid encryption!");
    } else {
     // If the shift value is the same as before, continue with the next number
     crackThatThing((clearText / 10), (cryptoText / 10));
    }
   } else {
    // The encryption is valid
    System.out.println("The encryption is valid. The shift is: " + shift);
   }
  }
 }

Any ideas?

Edit: Here’s what I think it should be

The following code is based on absolutely no previous experience with SML whatsoever, and since I actually deleted the code I had written, this is based on the bits I can remember. I know it’s wrong and very likely hideous code, but please bear with me on this one.

var notValid = "This is not a valid encryption!";
var valid = "The encryption is valid. The shift is: ";

var shift = 11; (* This is just to initialize it *)
var firstRun = true;

fun crackThatThing(clearText, cryptoText) =
if firstRun = true then
  firstRun = false andalso
  shift = ((cryptoText mod 10) - (clearText mod 10) mod 10) andalso
  crackThatThing(clearText div 10, cryptoText div 10)
else
  if clearText > 0 andalso cryptoText > 0 then
    if not (shift = ((cryptoText mod 10) - (clearText mod 10) mod 10)) then
      notValid
    else
      crackThatThing(clearText div 10, cryptoText div 10)
  else
    valid;
  • 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-25T14:51:44+00:00Added an answer on May 25, 2026 at 2:51 pm

    There exists plenty of books and resources on the net (See below).

    You need the functions div and mod and then some general functional principles, such as recursion to solve this.
    I’m not going to give you any code for this as it is a weekly assignment. However I’ll be more than happy to help on more specific issues not related to this assignment.

    Links

    • A Gentle Introduction to ML
    • Tips for Computer Scientists on Standard ML (Revised)
    • The Standard ML Basis Library
    • Programming in Standard ML ’97
    • Danish text: Supplerende noter i funktionsprogrammering (I can’t find a link to the newest version)

    All the examples I’ve seen only cover very simple if-else statements

    Then I would dare to say that you haven’t looked properly! See the list of links above, at least a few of them contains introductions to SML on different levels.

    the documentation of SML is ridiculous compared to other languages.

    You are not really referring to which documentation you are talking about, but I can only guess that it is not the definition/commentary. Anyways it seems you don’t know what you are talking about!

    My friends have been able to “convert” it to SML using two functions instead of just one, but it seems stupid to do that when it should be really simple.

    Indeed, and it is actually really simple once you understand the functional principles. Again I will be happy to give pointers on specific issues.

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

Sidebar

Related Questions

A couple of friends and I are working on a project for our final
Couple of friends and i will be building simple robot to track a white
I am working with couple of friends on an ASP.NET MVC website. The project
Hello friends I have an issue adding a special class to a couple of
I have an HTML file that I gave to a couple of friends. I
Hi I have been working on a Monopoly project for a couple of days
I am starting a Facebook application with a couple of friends. What good, free,
A couple of the options are: $connection = {my db connection/object}; function PassedIn($connection) {
I am doing standard FB.ui requests and feed posts which have been working more
I have a pretty large social network type site I have working on for

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.