Jump to content

Create an executable for a program in an interpreted language: Difference between revisions

Created Nim solution.
m (Use debian standard install location for J)
(Created Nim solution.)
Line 402:
 
Variations and further details are given in the [https://github.com/stedolan/jq/wiki/FAQq%20FAQ jq FAQ].
 
=={{header|Nim}}==
Nim is normally a compiled language which can produce either native code using C, C++ or Objective C as intermediate language, or a JavaScript program. It is not a language designed to be interpreted, but there exists a powerful subset named Nimscript which is interpretable.
 
So we have chosen to write a Nim program which launch the “nim” program to evaluate a Nimscript program. There are two ways to ask “nim” to interpret: either using the “e” command rather than the “c” command or using the “--eval” option.
 
<syntaxhighlight lang="Nim"># Using the "e" command.
 
import std/os
 
const TempFile = "/tmp/hello.nim"
const Program = """echo "Hello World!""""
 
# Write program into temporary file.
let outFile = open(TempFile, fmWrite)
outFile.writeLine Program
outFile.close()
 
# Lauch "nim" to execute the program.
# "--hints:off" suppresses the hint messages.
discard execShellCmd("nim e --hints:off " & TempFile)
 
# Remove temporary file.
removeFile(TempFile)
</syntaxhighlight>
 
<syntaxhighlight lang="Nim"># Using the '--eval" option.
 
import std/[os, strutils]
 
const Program = """echo "Hello World!""""
 
# As the program is provided in the command line, there is no need
# to create a temporary file.
 
# Lauch "nim" to execute the program.
# "--hints:off" suppresses the hint messages.
discard execShellCmd("""nim --hints:off --eval:'$#'""" % Program)
</syntaxhighlight>
 
{{out}}
<pre>Hello World!</pre>
 
=={{header|Phix}}==
256

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.