7
\$\begingroup\$

Intro

In Objective-C (a superset of C and an object-oriented language), I can create an object called a UIWebView. There is a method for this object called loadHTMLString: in which I can load actual HTML into the UIWebView object itself. I can also inject Javascript into it using the method stringByEvaluatingJavaScriptFromString:.

If I were to write a program that created a UIWebView, loaded in my string (which happens to be HTML "code") and then injected a second string (which is Javascript code) I would be using 3 languages at once, in a functional program. (Not sure that html is really a programming language... so that's debatable haha)

You can also do things like embed Python into C (and other languages): https://docs.python.org/2/extending/embedding.html


This isn't too difficult, with any language you can use other languages inside it if you try hard enough.


Challenge

The challenge here is to see how many languages you can cram into 1 functioning program in under 500 bytes. https://mothereff.in/byte-counter

The program can do literally any task, it just has to work. The languages all have to work together, so you can't have 2 languages running one task, and 3 other languages running a completely different task. So whatever your "task" may be (you decide), there should only be 1 task, and all n languages should work on just that 1 task in your 1 program.


Objective

Your score is the number of languages you used. Whoever uses the most languages at once gets a cookie.

Since this is a popularity contest I will be accepting the answer with the most up-votes.


Q&A

•Ray asked, "Just to clarify, you're looking for a program that uses multiple languages to accomplish different parts of a single task, as opposed to a polyglot that is a valid program in multiple languages?" Answer, "Yes".

•DanielM. asked, "does Regex count?" Answer, "Yes, I personally WOULD count it. Again, this is a popularity contest, so it really is up to the voters to determine. HTML is not considered a programming language by some, but it has been successfully used in an answer already that has seen quite a few upvotes. (Also, Stack-overflow does define Regex as a programming language if that helps you make your decision to use it or not: https://stackoverflow.com/tags/regex/info)

\$\endgroup\$

closed as too broad by Downgoat, Conor O'Brien, Alex A. Oct 8 '15 at 4:59

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ Just checking: I'm guessing 0 bytes isn't a valid answer? (Task: Does nothing) \$\endgroup\$ – Sp3000 Oct 7 '15 at 22:39
  • 2
    \$\begingroup\$ Can the task be "do nothing"? If we're trying to cram as many in as possible, it seems like any work or output would detract from the "purity" of that goal ;) \$\endgroup\$ – Geobits Oct 7 '15 at 22:47
  • 4
    \$\begingroup\$ If you're accepting the answer with the most languages used, this is no longer a popularity contest since the winner is not determined by votes. \$\endgroup\$ – Alex A. Oct 7 '15 at 22:52
  • 2
    \$\begingroup\$ The point of a popularity contest is that the answer with the most votes gets accepted. Challenges here need an objective winning criterion to be on topic. \$\endgroup\$ – Alex A. Oct 7 '15 at 22:57
  • 2
    \$\begingroup\$ Just to clarify, you're looking for a program that uses multiple languages to accomplish different parts of a single task, as opposed to a polyglot that is a valid program in multiple languages? \$\endgroup\$ – Ray Oct 7 '15 at 23:04
9
\$\begingroup\$

make, sh, awk, sed, regex, yacc, lex, C; 8 languages.

Including the input and output languages: brainfuck and D; 10 languages

This is a brainfuck to D compiler. It takes the brainfuck program over standard input and prints the D code to standard output.

Make uses awk, sed, and sh to generate a yacc program, which in conjunction with a lex program is used to generate a C program that takes a brainfuck program as input and outputs an equivalent D program. I tried to only use languages in ways that were actually useful, instead of just throwing in a bunch of no-ops. The lex/yacc/C combination is fairly standard for simple compilers, the make/sh combination is useful for building, and the awk/sed line was the only way I could get the whole thing under 500 bytes. (It's at 498 bytes currently.)

Code

define L
%%
[][+-<>.,] return *yytext;
. ;
%%
endef
define Y
%{
#include <stdio.h>
%}
%left '+' '-' '.' ',' '>' '<' '[' ']'
%%
q: q q {}
+ p[i]++
- p[i]--
> i++
< i--
, p[i]=getchar()
. putchar(p[i])
[ while(p[i]){
] }
%%
yywrap(){}yyerror(){}main(){puts("import std.stdio;int p[30000];int i;void main(){");yyparse();puts("}");}
endef
export L
export Y
a:
    @echo "$$L">y;lex y;echo "$$Y"|awk '/^[+-^]/{printf("q: X%sX {puts(\"%s;\");}\n",$$1,$$2)} /^[^+-^]/'|sed "y/X/'/">y;yacc y;cc *.c;./a.out;:

Example of use

$ cat helloworld.bf
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
$ make < helloworld.bf > tmp.d
y: warning: 8 shift/reduce conflicts [-Wconflicts-sr]
$ dmd tmp.d && ./tmp
Hello World!
\$\endgroup\$
  • \$\begingroup\$ Wow haha! I'd count the input language if I were you haha! Processing it is really neat, creative solution to sneak an extra language in \$\endgroup\$ – Albert Renshaw Oct 8 '15 at 2:37
  • \$\begingroup\$ Well, I think this answer is easily the best answer, but my question was put on hold and activity dropped, and since it's a "popularity contest" I have to chose the answer with the most votes, even though I think if it wasn't put [on hold] this would have easily been the first place answer. Sorry /: \$\endgroup\$ – Albert Renshaw Oct 9 '15 at 23:51
  • \$\begingroup\$ make, awk and sed can all be easily executed by sh, regex can be easily parsed by sed. So, -1. \$\endgroup\$ – Erik the Outgolfer Jun 28 '16 at 7:15
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ I agree with you on the regex, but the OP explicitly stated that regex should be counted, so I did. I'm not sure I understand what you mean about make, awk, and sed being easily executed by sh. I do call sed and awk from sh, although it's make that calls sh, not the other way around. That said, sh was mainly needed for the I/O redirection and echo command. awk was needed for the input tokenization and regex, and sed was needed for the transliteration. There were other ways to do all that, but not easily under 500 characters. (Besides, the point was to use many languages) \$\endgroup\$ – Ray Jun 30 '16 at 1:16
  • \$\begingroup\$ @Ray But you listed "sed" and "regex" separately, so I count them as one. Yet, you can say "make, dash, coreutils, yacc, lex". \$\endgroup\$ – Erik the Outgolfer Jun 30 '16 at 8:09
9
\$\begingroup\$

HTML, CSS, PHP, JavaScript, CoffeeScript, RegEx, sed, bash; 8 languages

Displays colors of the rainbow.

(Only 396 bytes) will try to add more languages

HTML + CSS is turning complete and counts as a valid language on PPCG. I've been told CoffeeScript is different enough as JavaScript to be counted as a separate language. And RegEx has been specifically allowed also.

PHP allows for addition of many languages especially with exec and shell_exec functions.

Golfed to fit inside byte limit (ES6)

<html><style><?php foreach(explode(" ",exec('sed "s/;/ /g"<<<"red;orange;yellow;green;blue;violet"')) as $color){echo "#{$color} { color: $color }\n"}?></style><script>b="red orange yellow green blue violet".split(/ /).map(c=>`<p id="${c}">${c}</p>`)</script><script type="text/coffeescript">document.documentElement.innerHTML+=b.join "\n"</script><script src="http://v.ht/u31R"></script></html>

Uses:

  • PHP to generate CSS
  • PHP, uses exec to run bash
  • sed to split color items for bash
  • CSS to specify text colors
  • JavaScript to generate elements
  • RegEx to split color items for JS
  • CoffeScript to print elements
  • HTML as a wrapper / output

Faster & Ungolfed (All modern browsers)

<html>
<style>
  /* CSS */
  <?php// Loop through all colors
  foreach(explode(" ",
  exec('sed "s/;/ /g"<<<"red;orange;yellow;green;blue;violet"')) as $color) {
    // Print it out, add it to the CSS
    echo"#{$color} { color: $color }\n"}
 ?>
</style>
  
<script>
  // Create an element for each color, store as variable
  window.colors = "red orange yellow green blue violet".split(/ /).map(function(color) {
    return "<p id=\"" + color + "\">" + color + "</p>"
  });
</script>
  
<script type="text/coffeescript">
  document.documentElement.innerHTML += window.colors.join "\n"
</script>
  
<!-- CoffeScript Link -->
<script src="https://raw.githubusercontent.com/jashkenas/coffeescript/master/extras/coffee-script.js"></script>

</html>

\$\endgroup\$
  • \$\begingroup\$ Very nice seamless combination of the languages at hand \$\endgroup\$ – Albert Renshaw Oct 8 '15 at 1:04
  • \$\begingroup\$ I sense a serious lack of XSLT. And the XPath that comes with it. \$\endgroup\$ – Édouard Oct 8 '15 at 4:04
  • \$\begingroup\$ @Édouard I've tried to implement that but it's difficult implementing that in under 100 bytes. JavaScript doesn't have very consise XSLT but I'm working on it \$\endgroup\$ – Downgoat Oct 8 '15 at 4:26
  • \$\begingroup\$ What do you mean “JS doesn’t have concise XSLT”? Are you trying to use JS to apply your transformation? \$\endgroup\$ – Édouard Oct 8 '15 at 4:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.