Polyglot (konputazioa)

Wikipedia, Entziklopedia askea

Konputazioan, polyglot bat programa informatiko edo script bitxia da, zenbait programazio-lengoaietan ondo idatzita dagoena, eragiketa edo irteera berdinak burutzen dituena, konpilatzeko edo interpretatzeko erabilitako lengoaiarekin independentea dena.

Gehien bat polyglotak C lengoaia eta script lengoaia (Lisp, Perl, Bash,...) baten arteko konbinaketak dira.

Exekuzioa[aldatu | aldatu iturburu kodea]

Iturburu kodea hainbat lengoaiaren sintaxia betetzeko idatzita egon daiteke. Era honetan, hainbat garatzailek erronka edo dibertsiotzat hartzen dute.

Polyglota hainbat lengoaiatan interpretatu daiteke, eta guztietan errendimendu bera edukiko du. Adibidez, programa hau C, PHP edo Bash programa bat bezala irakurri daiteke:

#define a /*
#<?php
echo "\010Hello, world!\n";// 2> /dev/null > /dev/null \ ;
// 2> /dev/null; x=a;
$x=5; // 2> /dev/null \ ;
if (($x))
// 2> /dev/null; then
return 0;
// 2> /dev/null; fi
#define e ?>
#define b */
#include <stdio.h>
#define main() int main(void)
#define printf printf(
#define true )
#define function
function main()
{
printf "Hello, world!\n"true/* 2> /dev/null | grep -v true*/;
return 0;
}
#define c /*
main
#*/

Hain famatuak ez diren lengoaiek ere aukera ematen dute Polyglot bat osatzeko. Adibide honetan SNOBOL4, Win32Forth, PureBasicv4.x, eta REBOL erabili dira:

*BUFFER : A.A ; .( Hello, world !) @ To Including?
Macro SkipThis; OUTPUT = Char(10) "Hello, World !"
;OneKeyInput  Input('Char', 1, '[-f2-q1]')  ; Char
End; SNOBOL4 + PureBASIC + Win32Forth + REBOL = <3
EndMacro: OpenConsole() : PrintN("Hello, world !")
Repeat : Until Inkey() :  Macro SomeDummyMacroHere
REBOL  [ Title:  "'Hello, World !' in 4 languages"
CopyLeft:  "Developed in 2010 by Society" ]  Print
"Hello, world !"  EndMacro:  func  [][]  set-modes
system/ports/input [binary: true] Input  set-modes
system/ports/input  [binary: false] NOP:: EndMacro
; Wishing to refine it with new language ? Go on !

Kanpo Loturak[aldatu | aldatu iturburu kodea]

Kanpo estekak[aldatu | aldatu iturburu kodea]