3
/* I hope such question is suitable for here*/
As the batch scripts are pretty limited, hybrid files that embed a code from another language into a batch file are used a lot lately.
Though usually there are some requirements for a good hybrid script:
- The embedded code should be usable as-it-is - without any ugly batch escaping sequences.
- There should not be redundant output. E.g. a lot of languages use /* */ for multi-line comments. If the batch script executes a line that starts with / * it will print an error message an will continue to the next line .Though it will allow you to hybridize C/C++/C#/Java/... with a batch file the error message cannot be surpassed so this will not count as a good hybrid.
- No temp files.It's easy to output a lot of code into a temp file that will be later executed , the IO operations will slow the script and on of the main advantages of batch scripting (the speed) will be lost. And more over is a challenging constraint. But this will be not possible for compiling languages and for extension sensitive languages.
Some examples will follow:
JScript (good for example as it comes with every windows installation) technique invented somewhere in the link by Tom Lavedas :
@if (true == false) @end /*
@echo off
cscript //nologo //e:javascript "%~dpnx0" %*
echo Output from the batch.
goto :EOF */
WScript.Echo('Output from the jscript.');
The output will be:
Output from the jscript.
Output from the batch.
The technique uses the JScript (javascript has no such thing) specific @ directives to make the code valid (or silent) both for both languages.
Another example (again with JScript) invented by Ryan Biesemeyer:
0</* :
@echo off
echo Output from the batch.
cscript /nologo /E:jscript %~f0 %*
exit /b %errorlevel%
*/0;
WScript.Echo('Output from the jscript.');
This time is used the redirection priority in batch scripts and 0</* :
will be parsed as 0:</*
.
Here are some info that can help you:
- every line that starts with @ will be silent - even the invalid commands.
- every line that starts with : will be taken as label in batch and will be not executed
- every line that starts with something like
<someWord : someWord
will be silent because of redirection priority - every line that starts with something like
digit<someWord : someWord
will be silent because of redirection priority (this time the output will be redirected to a stream).In this case will be best to use 0 - you can use
<space><tab> ; , =
at the beginning of every line - these will be ignored as standard delimiters in batch.Can be useful if some language use some of these as comment. - if you start a line with
%not_existing_variable%
it will be replaced with nothing.Could be useful if in some language comments start with percent. - If you finish a line with a caret
^
the next line will be appended at the end.With the caret in batch you can escape the new line.
here's a little bit more inspiration
And here's the challenge. Your script should be with .bat
or .cmd
extension . It should contain a code from another language - the code should be used by the second language as it is (no escapes symbols) .REPL tools are accepted with the condition of no escape symbols - except in the line where the REPL tool is invoked. There should not be redundant output. There should be not temp files (with the exception of compiling languages , and file extension sensitive languages - then the file should copy itself in the %TEMP% folder).
Each script should accept one command line argument which will be printed 5 (five) times . Both from the batch part of the code and from the second language prefixed by the language name (for the batch case it should be BATCH:
for example.If the second language is Ruby it should be RUBY:
)
For sure this will be not possible with every language , but for many it is achievable.
The winner should propose the most solutions with different languages (or if the language is the same a different kind of techniques should be used like in the two examples above).In case of equal number of solutions the first one wins.
Only read the first bit of the question so far, but you should use the sandbox to start with. You don't lose reputation from downvotes, and you can improve your challenge before posting it. The sandbox is a featured meta post, so you can see it in the yellow box at the right near the top of the page. It might be worth deleting the question and reposting it to the sandbox. – wizzwizz4 – 2016-01-28T17:08:18.410
What is the winning criterion? – Rɪᴋᴇʀ – 2016-01-28T17:09:44.120
Welcome to Programming Puzzles & Code Golf! All challenges on this site require an objective winning criterion, such as fewest bytes of source code (code golf), so that it's clear which entry should win. – Alex A. – 2016-01-28T17:10:03.247
@AlexA. - sorry. My first time here. I've added a winner criteria. – npocmaka – 2016-01-28T17:14:44.647
No problem! We're here to help. It's not clear what you mean by "propose the most solutions." Can you be more specific? – Alex A. – 2016-01-28T17:18:32.930
I do think this should be (temporarily) moved to the sandbox. Then you can edit it and people can comment on it in the place that that's meant to be done, and you can copy the final challenge text back here. – wizzwizz4 – 2016-01-28T17:20:31.923
@AlexA. edited. Hope it's more clear now.If not it's ok to be moves in the sandbox – npocmaka – 2016-01-28T17:21:37.327
1
I think it would benefit from more feedback from the community. What I recommend doing is posting the challenge as an answer here (the sandbox), then deleting this question. Once things are sorted out in the sandbox, this can be edited and undeleted or reposted. How does that sound?
– Alex A. – 2016-01-28T17:28:22.893@AlexA. - agreed.Can I put it myself in the sandbox? – npocmaka – 2016-01-28T19:10:28.653
You sure can! You just have to post it as an answer at the link I included in my previous comment. :) – Alex A. – 2016-01-28T20:00:00.667