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

(Further emphasised that the task is about creating an executable, not making the source "executable" by putting #! ... at the start)
 
(4 intermediate revisions by 4 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 381:
 
=={{header|jq}}==
{{incorrect||The task says "So, instead of supplying the source for the program, we just want to produce an executable for that specific program." - using #! requires the source be supplied.<br>Please look at some of the other samples.}}
This entry confines itself to the task (creating an executable) in computing environments that support the "shebang" technique.
A bash shell, for example, would suffice.
Line 401 ⟶ 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