0

I am trying to make a function to check whether the value is a prime number or not using tail recursive function, so please can someone help me with this

`

declare
fun {PrimeR X D}
   if X==2 orelse X==3 then 1
   elseif  X<2 andthen ((X mod D)==0) andthen D =< X then 0
   elseif ((X mod D)\=0) then 1
   else {PrimeR X D+1}
   end
end
{Browse {PrimeR 6 1}}

`

1 Answers1

0

Something along those lines if you want to use an iterative function

declare
fun {IsPrime X}
   fun {PrimeItter X N}
      case (X mod N) of 0 then X==N
      else {PrimeItter X N+1} end
   end
in
   {PrimeItter X 2}
end

{Browse {IsPrime 31}}
scsi
  • 13
  • 3