# Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) and outputs a simple incrementing function with one argument (x) that returns x + n but the function must be in a different language. Pretty simple!

This is code-golf, normal rules apply, shortest program wins.

Example: ><> to Python (Ungolfed)

!v"def i(x):"a"    return x+"ir!
>l?!;o


Input:

3


Output:

def i(x):
return x+3


EDIT: Anonymous functions and lambda expressions are allowed!

• How big can the input get? As far as I can tell, your example only works with single digit numbers for the ><> half of it. – Sp3000 Nov 9 '15 at 6:12
• In theory in should be able to use any (reasonable) input, but answers that only use a input that could maintain 1 digit are fully acceptable, I did consider reworking the example to correct this before posting but i figured ill leave it for simplicity stake. – Blake Lockley Nov 9 '15 at 6:32
• I don't see any definition for function BUT that we are supposed to write.. -_- – Optimizer Nov 9 '15 at 13:45
• When a function returns another function, it's called a closure. I don't know if this applies cross-language, though... – ETHproductions Nov 9 '15 at 15:31
• @ETHproductions I guess the goal is not to return a function object, but the source code of a function in that other language. – Paŭlo Ebermann Nov 9 '15 at 20:40

# Python to C++, 49 bytes 39 bytes

print"[](int x){return x+%d;}"%input()


Thanks @Mego !

Basically, this prints out lambda with the argument x and adds it to the input of the Python program.

# Japt → TeaScript, 5 bytes

U+"+x


This is pretty simple.

### Explanation

U+     // Input added to the string...
"+x  // This is the string

• Japt → Japt would be not only a palindrome, but horizontally mirror-able: U+"+U ;) – ETHproductions Nov 23 '15 at 2:47

# Fith to Forth, 28 bytes (non-competitive)

Fith was created after the challenge was posted.

": p " line " + ;" + + .


This pushes the first part, then reads the number, then pushes the last part. The two + words then concatenate the three strings, and . prints.

The output looks something like this:

: p 7 + ;


This defines a function named p, and as far as I know, it is the shortest method in Forth to define the necessary function.

# Chaîne to JavaScript ES6, 7 bytes

Again, assumes numeric input.

x=>x+{i
~~~~~~~
x=>x+   ; write that text
{  ; command sequence
i ; read input and push to stack
; implicit: take top entry on stack and pushes it to writing string
; implicit: close }
; implicit: print string


## Powershell to EmacsLisp, 37 bytes

function p($a){"(defun p(x)(+$a x)"}


## EmacsLisp to Powershell, 44 bytes

(defun p(x)(format"function p($a){%s+$a}"x))


# Ruby to Thue, 139 bytes

Not as short as i thought it should be, but I will post anyway. Thue may not be the best language for golfing in.

10.times{|n|puts "#{n}+::=#{n==9?'+':''}#{(n+1)%10}\n#{n}|::=|*#{n}\n>#{n}::=~#{n}"};puts "_::=:::\n||::=<\n<*::=<>\n::=\n|_#{'+'*($*[0]).to_i}|"  Takes a command-line augment in ruby, and regular input in Thue. # Pyth to C++, 32 bytes %"[](int x){return x+%d;}"Q  Just a Pyth version of my Python one. # Python to Pyth, 20 bytes print"L+%db"%input()  Basically, it prints out a lambda function (L) that takes in the argument (b, implicit variable) and adds the input from the Python program. • @BadCatEye fixed it.. – TanMath Nov 12 '15 at 21:43 # Python to Lisp - 34 36 Bytes print"(lambda (x) (+ x %s))"%input()  # Python3 → Go, 89 bytes print('package main;import"fmt";func main(){a()};func a(x int)int{fmt.Println(x+'+input()+')}')  also a full program which compiles/runs with any of go build, go install or go run. if we allow just a function (which is an error/will not compile) then 47 bytes: print('func a(x int)int{return x+'+input()+'}')  # Go → Python (any version), 109 bytes package main;import"fmt";func main(){var a string;_,_=fmt.Scanln(&a);fmt.Println("def a(x):\n return x+"+a)}  ## Seriously to K, 4 bytes '+,+  Everyone else is posting "to K" answers, I might as well too. Takes input in the form of a string ("3.14"). Try it online # Go → LOLCODE, 192 bytes package main;import."fmt";func main(){a:="";Scanln(&a);Println("HAI1.3\nHOW IZ I ADDIN YR X\nI HAS A VAR\nVAR R SUM OF X AN "+a+"\nVISIBLE VAR\nIF U SAY SO\nKTHXBYE")}  the resulting output compiles with lci. # C# to Mathematica, 85 81 bytes using C=System.Console;class C{static void Main(){C.Write(C.ReadLine()+"+#&");}}  Outputs a Mathematica Function of form n+#&  • In the first programming language (C# in your case) you should write a full program (which reads input and produces output), not just a single function. – Paŭlo Ebermann Nov 11 '15 at 19:21 • @PaŭloEbermann "EDIT: Anonymous functions and lambda expressions are allowed!" – LegionMammal978 Nov 11 '15 at 21:57 • This is for the created function, not the creating one ... see my comment at the question about this and the OP's answer to it (which were both later than this edit). – Paŭlo Ebermann Nov 11 '15 at 22:00 • Save 4 bytes by replacing WriteLine with Write – Metoniem Feb 20 '17 at 9:47 # Java (OpenJDK 8) -> Python 3, 155 153 bytes import java.util.Scanner;class Main{public static void main(String[] args){Scanner s=new Scanner(System.in);System.out.println("lambda x:x+"+s.next());}}  Try it online! Not exactly a winning combination but it gave me a chance to practice using java. Saved 2+ bytes thanks to @WheatWizard • You could probably save bytes by writing out to a python lambda function. "lambda x:x+". – Ad Hoc Garf Hunter Feb 21 '17 at 0:21 • @WheatWizard thanks – Comrade SparklePony Feb 21 '17 at 14:46 • You don't need spaces on the sides of your equals signs add well. – Ad Hoc Garf Hunter Feb 21 '17 at 14:55 • Why did you remove the target language from the title? – Paŭlo Ebermann Nov 8 '19 at 12:31 • @PaŭloEbermann I think this was my first or second answer on this site, so I didn’t really know what I was doing. It’s fixed now. – Comrade SparklePony Nov 9 '19 at 15:04 # Batch → K, 8 bytes echo;%1+  Fun fact: you don't have to use a space to separate echo from the text to be echo-ed, but you can pick from a whole series of different characters. For example: ., ,, :, ; and some others. ## QBIC to Jelly, 6 bytes (NC) ;?A+@+  Given n=3, this will output the Jelly code 3+. When another number is passed to this link, it will add 3 to it. Try that online! The QBIC code: ; Read cmd line param as A$
?A  PRINT A\$
+@+ plus the string literal '+'
The string literal is auto-closed by QBIC at EOF.

• This answer is non-competing, as QBIC and Jelly are newer than this challenge. – Erik the Outgolfer Feb 20 '17 at 13:47
• @EriktheOutgolfer Thanks. hadn't noticed the date of the challenge. Marked it as NC. – steenbergh Feb 20 '17 at 13:51

# Java -> C (GCC) 144 134 bytes

class m{public static void main(String[]a){System.out.print(String.format("a(b){return %s+b;}",a[0]));}}


Takes the number(string, it is supposed to be a number, no error checking) as the first argument and prints the function to stdout.

# Clojure -> JavaScript, 14 bytes

#(str"a=>a+"%)


An anonymous function in Clojure that returns an anonymous function in JavaScript (and potentially a few other languages). % is the implicit n.

(#(str"a=>a+"%) 3)

"a=>a+3"


# Haskell -> Clojure, 25 bytes

\n->"#(+ % "++show n++")"


Anonymous Haskell function which takes n, and returns an anonymous Clojure function.

let f = \n->"#(+ % "++show n++")"

f 3

#(+ % 3)


# sB~ -> Befunge, 7 bytes (non-competing)

iN?N;+


Explained:

i N 'input N
?N;+ 'print N and "+"