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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:18:38+00:00 2026-06-15T20:18:38+00:00

I am developping a small Anti-Missile Simulator for a Class Project. The Idea is

  • 0

I am developping a small Anti-Missile Simulator for a Class Project.

The Idea is to have different processes/threads comunicating with each other.

I started working on the Missile Laucher application. Its missile has to be a thread.

So this is the start code I made:

open Missile;;

(* Name of the Station *)
let launcher_name = "Pacific";;

(* Gravitational Constant *)
let g = 9.8;;

(* Temporal Reference *)
let time = ref 0.0;;

(* Calculates the next position in time of the missile *)
let calculate_position () = 
  let nX = 10.0 *. !time and nY = (0.5) *. g**2.0 in (nX,nY);;

(* Launches the thread missile and updates its position *)
let launch mis = 
  while true do 

    let pos = mis#position () in 
    Printf.printf "%s\n" pos;


    let (a,b) = calculate_position () in
    mis#moveto (a,b);
    time := !time +. 1.0;

    (* Why isnt this working? *)
    Thread.delay 0.25 

  done;;



(* test function *)
let launchMissile () = 
  Printf.printf "Launch Station %s launched a missile. \n" launcher_name;
  let mis  = new missile "Test" 1 "USA" in
  let t1 = Thread.create launch mis in
  Thread.join t1;;



launchMissile ();;

After doing this I wanted to test my CalculatePosition function by printing the values over time.

But without a pause or wait they print out too fast, obviously. So I thought about delay the thread 0.25 s in each of the while iteration.

What am I doing wrong? I tried so many different things. Its only the Thread.delay function that it is behaving strange.

Can I do this ?

If you could help it would be great, I have ran out of thought on this… and started rereading all the books I have here on Ocaml.

If it is also important for you to analyze the problem here is my Missile Class:

class missile name id owner = 
object
  val mutable name = name;
  val id = id;
  val owner = owner;
  val mutable x:float = 0.0
  val mutable y:float = 0.0
  method get_x = x
  method get_y = y
  method get_point = (x,y)
  method moveto (a,b) = x <- a; y <- b
  method rmoveto (dx, dy) = x <- x +. dx ; y <- y +. dy
  method to_string () = "( " ^ "I am Missile " ^ (string_of_int id) ^ " and my owner is   " ^ (owner) ^ ")";
  method position () = "(" ^ (string_of_float x) ^ "," ^ (string_of_float y) ^ ")";
  method distance () = sqrt (x*.x +. y*.y)
end;;

Thank you

  • 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-15T20:18:39+00:00Added an answer on June 15, 2026 at 8:18 pm

    Printf.* functions are buffered (because of formatting features I suppose), while print_* and prerr_* are not. If you replace your printf by print_endline, you will see your output happening as expected, without having to flush the buffers.

    So this has nothing to do with buffer contentions or concurrent accesses as I originally stated, but just plain internal (not system) buffering.

    A few remarks in passing : you don’t need to put semi-colon at the end of methods (though the grammar accepts it). Also, parentheses around expressions are superfluous between ^ operators. Both are a matter of style I guess.

    Enjoy OCaml!

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

Sidebar

Related Questions

I'm developping a small UML Class editor in Java, mainly a personal project, it
I'm developping a new module and I have a small question. In the purchase
I am developping a 1 to many server-client application, which is a small project.
I am developping a small training ASP .Net web application. I have developped an
I am developping a small wormy program with PyGame. I have a worm eating
I'm developping a card game. I have an ASP.NET page with some 52 small
I'm developing small FTP upload app. for mac (10.6 if it matters) Have problem
I have a little experience developing small command-line applications with Python. I want to
I'm developing a small application using Blend, basically what I have in my application
I'm developing a small web framework using Guice. I have a Router object that,

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.