# prime.rb for Unix # one of the sample Ruby/Mathematica require 'mathematica/mathlink' include Mathematica include MathLink argv = ['-linkname', 'math -mathlink'] link = MathLink.new.open(argv.size, argv) print 'Please type positive number:' num = STDIN.gets link.put_function('Prime', 1) link.put_integer(num) link.end_packet link.new_packet while(link.next_packet != RETURNPKT) printf "%d-th prime number is %d.\n", num, link.get_integer exit