I've been working on my own programming language called greenServeFE, and I wanted to try something practical with it.
Instead of writing another basic example with loops or printing numbers, I decided to solve a simple physics problem using two native modules: gs_physics and gs_compute.
The problem is:
A ball starts from rest and falls freely for 3 seconds. Assume gravity is 9.8 m/s².
We need to calculate the distance travelled and the final velocity.
Here is the greenServeFE code:
import gs_compute;
import gs_physics;
define g = 9.8;
define time = 3;
define initial_velocity = 0;
define distance = gs_physics.displacement(initial_velocity, time, g);
define final_velocity = gs_physics.final_velocity(initial_velocity, g, distance);
define time_squared = gs_compute.multiply(time, time);
define half_g = gs_compute.multiply(0.5, g);
define compute_distance = gs_compute.multiply(half_g, time_squared);
define compute_velocity = gs_compute.multiply(g, time);
print("FREE FALL PHYSICS");
print("Initial velocity (m/s):");
print(initial_velocity);
print("Time (s):");
print(time);
print("Gravity (m/s^2):");
print(g);
print("Distance using gs_physics (m):");
print(distance);
print("Final velocity using gs_physics (m/s):");
print(final_velocity);
print("Distance checked using gs_compute (m):");
print(compute_distance);
print("Velocity checked using gs_compute (m/s):");
print(compute_velocity);
I used gs_physics for the physics calculations. The displacement function calculates the distance, and the final velocity function calculates the velocity after falling.
I also used gs_compute to check the results with basic multiplication.
This is the output from running the program in Cloud Shell:
developerdominex@cloudshell:~$ greenServeFE physics.gsve
FREE FALL PHYSICS
Initial velocity (m/s):
0
Time (s):
3
Gravity (m/s^2):
9.8
Distance using gs_physics (m):
44.1
Final velocity using gs_physics (m/s):
29.4
Distance checked using gs_compute (m):
44.1
Velocity checked using gs_compute (m/s):
29.4
Both modules give matching results:
- Distance travelled: 44.1 metres
- Final velocity: 29.4 metres per second
Top comments (0)