Use another language to call a function: Difference between revisions

Content deleted Content added
Line 761:
-L"`ocamlc -where`" \
-lm -ldl -lasmrun
 
=={{header|PARI/GP}}==
 
This is a Linux solution. Message "Here I am" is encrypted with ROT13: "Urer V nz".
 
ROT13() is implemented as a PARI one-line:<lang parigp>Strchr(Vecsmall(apply(k->if(k>96&&k<123,(k-84)%26+97,if(k>64&&k<91,(k-52)%26+65,k)),Vec(Vecsmall(s)))))</lang>
PARI's interface to Query()...
<lang C>#include <pari/pari.h>
 
#define PARI_SECRET "s=\"Urer V nz\";Strchr(Vecsmall(apply(k->if(k>96&&k<123,(k-84)%26+97,if(k>64&&k<91,(k-52)%26+65,k)),Vec(Vecsmall(s)))))"
 
int Query(char *Data, size_t *Length)
{
int rc = 0;
GEN result;
 
pari_init(1000000, 2);
 
result = geval(strtoGENstr(PARI_SECRET)); /* solve the secret */
 
if (result) {
strncpy(Data, GSTR(result), *Length); /* return secret */
rc = 1;
}
 
pari_close();
 
return rc;
}</lang>
 
Compile interface to a library: gcc -O2 -Wall -fPIC -shared query.c -o libquery.so -lpari
 
Compile main() C code from above and link against this library: gcc -O2 -Wall main.c -o main -L. libquery.so
 
Start main(): LD_LIBRARY_PATH=. ./main
 
PARI solves the ROT13 encrypted message and returns result to caller.
 
Output:<pre>Here I am</pre>
 
 
=={{header|Pascal}}==