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

(→‎{{header|jq}}: Flagged as incorrect, unfortunately but thanks for attempting the task)
 
(3 intermediate revisions by 3 users not shown)
Line 356:
I think this task is a duplicate of another task. But it's also about the host operating system.
 
<syntaxhighlight lang="j">#!/usr/local/bin/jconsoleijconsole
echo 'hello world'
exit 0</syntaxhighlight>
Line 402:
 
Variations and further details are given in the [https://github.com/stedolan/jq/wiki/FAQq%20FAQ jq FAQ].
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
using StaticCompiler, StaticTools
 
hello() = println(c"Hello world!") # the c"" syntax defines a static C type string
compile_executable(hello, (), "./") # can now run this as executable "hello"
</syntaxhighlight>{{out}}
<pre>
$ ./hello
Hello world!
</pre>
 
=={{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}}==
4,102

edits