[Question]
  [
To "function nest" a string, you must:
* Treat the first character as a function, and the following characters as the arguments to that function. For example, if the input string was `Hello`, then the first step would be:
```
H(ello)
```
* Then, repeat this same step for every substring. So we get:
```
H(ello)
H(e(llo))
H(e(l(lo)))
H(e(l(l(o))))
```
Your task is to write a program or function that "function nests" a string. For example, if the input string was `Hello world!`, then you should output:
```
H(e(l(l(o( (w(o(r(l(d(!)))))))))))
```
The input will only ever contain [printable ASCII](https://en.wikipedia.org/wiki/ASCII#Printable_characters), and you may take the input and the output in any reasonable format. For example, STDIN/STDOUT, function arguments and return value, reading and writing to a file, etc.
For simplicity's sake, you may also assume the input will not contain parentheses, and will not be empty.
```
Input:
Nest a string
Output:
N(e(s(t( (a( (s(t(r(i(n(g))))))))))))
Input:
foobar
Output:
f(o(o(b(a(r)))))
Input:
1234567890
Output:
1(2(3(4(5(6(7(8(9(0)))))))))
Input:
code-golf
Output:
c(o(d(e(-(g(o(l(f))))))))
Input:
a
Output:
a
Input:
42
Output:
4(2)
```
As usual, all of our default rules and loopholes apply, and the shortest answer scored in bytes wins!
  
[Answer]
# Python, ~~41~~ ~~39~~ 34 bytes
```
lambda e:"(".join(e)+")"*~-len(e)
```
[Ideone it](http://ideone.com/6zHzp5)
Pretty self explanatory.
It puts a parenthesis between every other character then adds one less than the length parentheses to the end.
[Answer]
## MS-DOS .com file, 30 bytes
```
0000   fc be 82 00 b4 02 ac 88 c2 cd 21 ac 3c 0d 74 0d
0010   b2 28 50 cd 21 5a e8 f0 ff b2 29 cd 21 c3
```
The string is passed to the executable using the command line. (One space character between the .COM file name and the string).
The result is written to standard output.
The disassembly is here:
```
  fc          cld              ; Make sure DF is not set (lodsb!)
  be 82 00    mov    si,0x82   ; First character of command line args
  b4 02       mov    ah,0x2    ; AH=2 means output for INT 21h
  ac          lodsb            ; Load first character
  88 c2       mov    dl,al     ; Move AL to DL (DL is written to output)
recursiveFunction:
  cd 21       int    0x21      ; Output
  ac          lodsb            ; Get the next character
  3c 0d       cmp    al,0xd    ; If it is "CR" (end of command line) ...
  74 0d       je     doReturn  ; ... return from the recursive function
  b2 28       mov    dl,0x28   ; Output "(" next...
  50          push   ax        ; ... but save character read first
  cd 21       int    0x21      ; (Actual output)
  5a          pop    dx        ; Restore character (but in DL, not in AL)
  e8 f0 ff    call   recursiveFunction  ; Recursively enter the function
doReturn:
  b2 29       mov    dl,0x29   ; Output ")"
  cd 21       int    0x21
  c3          ret              ; Actually return
```
Note: You can exit a DOS .COM file (unlike files with EXE headers) using a "RET" instruction.
[Answer]
## JavaScript (ES6), ~~40~~ ~~34~~ 33 bytes
*Saved 6 bytes, thanks to ETHproductions*
A recursive function.
```
f=([c,...s])=>s+s?c+`(${f(s)})`:c
```
[Try it online!](https://tio.run/##dY/dCoJAEIXve4olujhLqWX2C9Yb9AIRtG3uYogbO9JN9Ow2goJIzTAwF@c7Z@ahXoq0z59VULp7VtcmxVnPwjCki0wPNKWjnl4xeRuQ/MjrXtfaleSKLCychcH4lFEllKDK56UdSymiSJyQgVBBQPE0m0eOElb2ajQwMs7dlG8c2mIjA8d9Yxv/k1nEy2S13mx385ZjZoEYSyRYYY0Ntthh/jdT88@BdYXpYpnXnHjnBwJY3gqYf7Dq3drBaihK4oGKRQliWX8B "JavaScript (Node.js) – Try It Online")
[Answer]
# Brainfuck, ~~42~~ 40 bytes
```
>+[-->+[<]>-]>+>>,.,[<+<.>>.,]<<+>[-<.>]
```
[Try it online!](http://brainfuck.tryitonline.net/#code=PitbLS0-K1s8XT4tXT4rPj4sLixbPCs8Lj4-LixdPDwrPlstPC4-XQoK&input=dGVzdA)
Ungolfed:
```
>+[-->+[<]>-]>+     # count to 40 (ASCII for open paren)
>>                  # move to the input holder
,.                  # input the first byte and output it
,                   # input the next byte
[                   # while it's not zero
  <+                # move to the input counter and increment it
  <.                # move to the open paren and output it
  >>.               # move to the input holder and output it
  ,                 # input the next byte
]
<<+                 # move to the open paren and increment it to a close
>                   # move to the input counter
[                   # while it's not zero
  -                 # decrement it
  <.                # move to the close paren and output it
  >                 # move to the input counter
]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 11 bytes
```
S'(ý¹g<')×J
```
[Try it online!](http://05ab1e.tryitonline.net/#code=Uycow73CuWc8JynDl0o&input=TmVzdCBhIHN0cmluZw)
**Explanation:**
```
S'(ý         join input by "("
    ¹g<      push length of input - 1, call it n
       ')×   push a string with char ")" n times
          J  concatenate
```
[Answer]
# Brainfuck, 44 bytes
```
>+++++[-<++++++++>],.,[<.>.>+<,]<+>>[-<<.>>]
```
Reads a byte at a time, puts an open-paren before each one except the first, puts the same number of close-parens at the end.
[Answer]
## Haskell, 30 bytes
```
f[x]=[x]
f(a:b)=a:'(':f b++")"
```
Usage example: `f "Nest a string"` -> `"N(e(s(t( (a( (s(t(r(i(n(g))))))))))))"`.
Take the next char, followed by a `(`, followed by a recursive call with all but the first char, followed by a `)`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~9~~ 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 byte thanks to @Dennis (use mould, `ṁ`, in place of length, `L`, and repeat, `x`)
```
j”(³”)ṁṖ
```
**[TryItOnline](http://jelly.tryitonline.net/#code=auKAnSjCs-KAnSnhuYHhuZY&input=&args=Y29kZS1nb2xm)**
### How?
```
j”(³”)ṁṖ - Main link: s     e.g. "code-golf"           printed output:
j        - join s with
 ”(      - literal '('           "c(o(d(e(-(g(o(l(f"
    ”)   - literal ')'
      ṁ  - mould like
   ³     - first input, s        ")))))))))"
         - causes print with no newline of z:          c(o(d(e(-(g(o(l(f
       Ṗ - pop (z[:-1])          "))))))))"            c(o(d(e(-(g(o(l(f
         - implicit print                              c(o(d(e(-(g(o(l(f))))))))
```
[Answer]
## [Retina](http://github.com/mbuettner/retina), ~~22~~ 17 bytes
```
\1>`.
($&
T`(p`)_
```
[Try it online!](http://retina.tryitonline.net/#code=XDE-YC4KKCQmClRgKHBgKV8&input=TmVzdCBhIHN0cmluZw)
Alternatively:
```
S_`
\`¶
(
T`(p`)_
```
### Explanation
I always forget that it's possible to print stuff along the way instead of transforming everything into the final result and outputting it in one go...
```
\1>`.
($&
```
Here `\` tells Retina to print the result of this stage without a trailing linefeed. The `1>` is a limit which means that the first match of the regex should be ignored. As for the stage itself, it simply replaces each character (`.`) except the first with `(` followed by that character. In other words, it inserts `(` in between each pair of characters. For input `abc`, this transforms it into (and prints)
```
a(b(c
```
All that's left is to print the closing parentheses:
```
T`(p`)_
```
This is done with a transliteration which replaces `(` with `)` and deletes all other printable ASCII characters from the string.
[Answer]
# J, 13 bytes
```
(,'(',,&')')/
```
J executes from right-to-left so using the insert adverb `/`, a verb can be used to reduce the letters of the input string.
## Usage
```
   f =: (,'(',,&')')/
   f 'Nest a string'
N(e(s(t( (a( (s(t(r(i(n(g))))))))))))
   f 'foobar'
f(o(o(b(a(r)))))
   f '1234567890'
1(2(3(4(5(6(7(8(9(0)))))))))
   f 'code-golf'
c(o(d(e(-(g(o(l(f))))))))
```
You can observe the partial outputs between each reduction.
```
   |. f\. 'Hello'
o            
l(o)         
l(l(o))      
e(l(l(o)))   
H(e(l(l(o))))
```
## Explanation
```
(,'(',,&')')/  Input: string S
(          )/  Insert this verb between each char and execute (right-to-left)
      ,&')'      Append a ')' to the right char
  '(',           Prepend a '(' to that
 ,               Append to the left char
```
[Answer]
## [><>](http://esolangs.org/wiki/Fish), ~~19~~ 18 bytes
```
io8i:&0(.')('o&!
o
```
[Try it online!](http://fish.tryitonline.net/#code=aW84aTomMCguJykoJ28mIQpv&input=SGVsbG8gV29ybGQh)
### Explanation
The first line is an input loop which prints everything up to the last character of the input (including all the `(`) and leaves the right amount of `)` on the stack:
```
io                 Read and print the first character.
  8                Push an 8 (the x-coordinate of the . in the program).
   i               Read a character. Pushes -1 at EOF.
    :&             Put a copy in the register.
      0(           Check if negative. Gives 1 at EOF, 0 otherwise.
        .          Jump to (8, EOF?). As long as we're not at EOF, this is
                   a no-op (apart from popping the two coordinates). At EOF
                   it takes us to the second line.
         ')('      Push both characters.
             o     Output the '('.
              &    Push the input character from the register.
               !   Skip the 'i' at the beginning of the line, so that the next
                   iteration starts with 'o', printing the last character.
```
Once we hit EOF, the instruction pointer ends up on the second line and we'll simply execute `o` in a loop, printing all the `)`, until the stack is empty and the program errors out.
[Answer]
# C#, 32 bytes
```
F=s=>*s+++(0<*s?$"({F(s)})":"");
```
This lambda must be a static method, would I need to count any extra bytes for that requirement? Normally I wouldn't use a lambda for recursion in C#, but then I think it would be shorter not to use recursion.
```
/*unsafe delegate string Function(char* s);*/ // Lambda signature
/*static unsafe Function*/ F = s =>
    *s++                               // Take first char and increment pointer to next one
    + (0 < *s                          // Check if any chars left
        ? $"({F(s)})"                  // If so concat surrounding parens around recursion
        : ""                           // Otherwise done
    )
;
```
[Answer]
# Java 7,~~81~~ 79 bytes
*Saved `1` byte.Thanks to kevin.*
```
String f(char[]a,String b,int l){return l<a.length?f(a,b+'('+a[l],++l)+')':b;}
```
[Answer]
# R, 61 bytes
```
cat(gsub("(?<=.)(?=.)","(",x,F,T),rep(")",nchar(x)-1),sep="")
```
Regex finds and replaces spaces between characters with "(". Then `cat` and `rep` add ")" n-1 times at the end.
[Answer]
## PowerShell v2+, 46 bytes
```
param([char[]]$a)($a-join'(')+')'*($a.count-1)
```
Takes input string, `char`-array's it, `-join`s the array together with open parens `(`, then concatenates on the appropriate number of closed parens `)`.
[Answer]
# APL, 19 bytes
```
{∊('(',¨⍵),')'⍴⍨⍴⍵}
```
Explanation:
```
{
  ('(',¨⍵)          ⍝ join a ( to each character in ⍵          
          ,')'⍴⍨⍴⍵  ⍝ for each character in ⍵, add an ) to the end
 ∊                  ⍝ flatten the list 
                   }
```
Alternative solution, also 19 bytes:
```
{⊃{∊'('⍺⍵')'}/⍵,⊂⍬}
```
Explanation:
```
{              
              ⍵,⊂⍬  ⍝ add an empty list behind ⍵ (as a base case)
  {         }/      ⍝ reduce with this function:
    '('⍺⍵')'        ⍝   put braces around input
   ∊                ⍝   flatten the list
 ⊃                  ⍝ take first item from resulting list
                   }
```
[Answer]
# [MATL](http://github.com/lmendo/MATL), 16 bytes
```
t~40+v3L)7MQ3L)h
```
[Try it online!](http://matl.tryitonline.net/#code=dH40MCt2M0wpN01RM0wpaA&input=J2Zvb2Jhcic)
### Explanation
```
t     % Implicit input. Duplicate
      % STACK: 'foobar', 'foobar'
~     % Negate. Transforms into an array of zeros
      % STACK: 'foobar', [0 0 0 0 0 0]
40+   % Add 40, element-wise. Gives array containing 40 repeated
      % STACK: 'foobar', [40 40 40 40 40 40]
v     % Concatenate vertically. Gives a two-row char array, with 40 cast into '('
      % STACK: ['foobar'; '((((((']
3L)   % Remove last element. Converts to row vector
      % STACK: 'f(o(o(b(a(r'
7M    % Push array containing 40 again
      % STACK: 'f(o(o(b(a(r', [40 40 40 40 40 40]
Q     % Add 1, element-wise 
      % STACK: 'f(o(o(b(a(r', [41 41 41 41 41 41]
h     % Concatenate horizontally, with 41 cast into ')'
      % STACK: 'f(o(o(b(a(r)))))'
      % Implicit display
```
[Answer]
## [*Acc!!*](https://codegolf.stackexchange.com/a/62493/16766), 129 bytes
Not bad for a fairly verbose Turing tarpit...
```
N
Count i while _%128-9 {
Count x while _/128%2 {
Write 40
_+128
}
Write _%128
_+128-_%128+N
}
Count j while _/256-j {
Write 41
}
```
(Yes, all that whitespace is mandatory.)
**Note:** because of the input limitations of *Acc!!*, it is impossible to read an arbitrary string of characters without some ending delimiter. Therefore, this program expects input (on stdin) as a string followed by a tab character.
### *Acc!!*?
It's a language I created that [only appears to be unusable](https://codegolf.stackexchange.com/questions/61804/create-a-programming-language-that-only-appears-to-be-unusable). The only data type is integers, the only control flow construct is the `Count x while y` loop, and the only way to store data is a single accumulator `_`. Input and output are done one character at a time, using the special value `N` and the `Write` statement. Despite these limitations, I'm quite sure that *Acc!!* is Turing-complete.
### Explanation
The basic strategy in *Acc!!* programming is to use mod `%` and integer division `/` to conceptually partition the accumulator, allowing it to store multiple values at once. In this program, we use three such sections: the lowest-order seven bits (`_%128`) store an ASCII code from input; the next bit (`_/128%2`) stores a flag value; and the remaining bits (`_/256`) count the number of close-parens we will need.
Input in *Acc!!* comes from the special value `N`, which reads a single character and evaluates to its ASCII code. Any statement that consists solely of an expression assigns the result of that expression to the accumulator. So we start by storing the first character's code in the accumulator.
`_%128` will store the most recently read character. So the first loop runs while `_%128-9` is nonzero--that is, until the current character is a tab.
Inside the loop, we want to print `(` *unless* we're on the first iteration. Since *Acc!!* has no if statement, we have to use loops for conditionals. We use the 128's bit of the accumulator, `_/128%2`, as a flag value. On the first pass, the only thing in the accumulator is an ASCII value < 128, so the flag is 0 and the loop is skipped. On every subsequent pass, we will make sure the flag is 1.
Inside the `Count x` loop (whenever the flag is 1), we write an open paren (ASCII `40`) and add 128 to the accumulator, thereby setting the flag to 0 and exiting the loop. This also happens to increment the value of `_/256`, which we will use as our tally of close-parens to be output.
Regardless of the flag's value, we write the most recent input char, which is simply `_%128`.
The next assignment (`_+128-_%128+N`) does two things. First, by adding 128, it sets the flag for the next time through the loop. Second, it zeros out the `_%128` slot, reads another character, and stores it there. Then we loop.
When the `Count i` loop exits, we have just read a tab character, and the accumulator value breaks down like this:
* `_%128`: `9` (the tab character)
* `_/128%2`: `1` (the flag)
* `_/256`: number of characters read, minus 1
(The minus 1 is because we only add 128 to the accumulator once during the first pass through the main loop.) All that we need now are the close-parens. `Count j while _/256-j` loops `_/256` times, writing a close-paren (ASCII `41`) each time. Voila!
[Answer]
# Ruby, 27 bytes
```
->s{s.chars*?(+?)*~-s.size}
```
## Explanation
```
->s{                       # Declare anonymous lambda taking argument s
    s.chars                # Get the array of chars representing s
           *?(             # Join the elements back into a string using "("s as separators
              +?)*~-s.size # Append (s.size - 1) ")"s to the end
```
[Answer]
# Perl, ~~24~~ 23 bytes
Includes +1 for `-p`
Give string on STDIN ***without*** newline (or add a `-l` option to the program)
```
echo -n Hello | nest.pl
```
`nest.pl`:
```
#!/usr/bin/perl -p
$\=")"x s/.(?=.)/$&(/g
```
[Answer]
# PHP, 63 Bytes
```
<?=str_pad(join("(",$s=str_split($argv[1])),count($s)*3-2,")‌​");
```
Previous version 64 Bytes
```
<?=join("(",$s=str_split($argv[1])).str_pad("",count($s)-1,")");
```
[Answer]
## Perl, 25 bytes
*Thanks to [@Ton Hospel](https://codegolf.stackexchange.com/users/51507/ton-hospel) for golfing out 4 bytes.*
24 bytes of code + `-F`.
```
$"="(";say"@F".")"x$#F
```
Needs `-F` and `-E` flags :
```
echo -n "I love lisp" | perl -F -E '$"="(";say"@F".")"x$#F'
```
Note that if you try this on an old version of perl, you might need to add `-a` flag. 
---
Another interesting way (a little bit longer though : 28 bytes) :  
Thanks to Ton Hospel once again for helping me getting this one right.
```
#!/usr/bin/perl -p
s/.(?=.)/s%\Q$'%($&)%/reg
```
(To use it, put the code inside a file and call it with `echo -n "Hello" | perl nest.pl`)
[Answer]
# GNU sed, ~~37~~ ~~35~~ 31 bytes (30 +1 for `-r` argument)
Pure linux sed solution
```
:;s/([^(])([^()].*)$/\1(\2)/;t
```
1. Naming the subsitution `:`; then calling it recursively with `t`
2. Making 2 regex groups:
	* First group is first char of two consecutive characters which are *not* parenthesis
	* Second group is the second consecutive character and the rest of the string until end of line
3. Add parenthesis around the second group `\1 ( \2 )`
**Edit**: Thanks to @manatwork for helping removing 4 characters!
[Online tester](http://sed.tryitonline.net/#code=OjtzLyhbXihdKShbXigpXS4qKSQvXDEoXDIpLzt0&input=TmVzdCBhIHN0cmluZwpIZWxsbwpIZWxsbyB3b3JsZApmb29iYXIKMTIzNDU2Nzg5MApjb2RlLWdvbGYKYQo0Mgo&args=LXI)
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~22~~ ~~21~~ ~~19~~ 18 bytes
```
¤Ug<©FN¹è'(}X®')×J
```
[Try it online!](http://05ab1e.tryitonline.net/#code=wqRVZzzCqUZOwrnDqCcofVjCricpw5dK&input=Zm9v)
**Explanation:**
```
¤Ug<©FN¹è'(}X®')×J #implicit input, call it A                                 
¤U                 #push the last letter of A, save it to X
  g<©              #push the length of A, subtract 1, call it B and save it to register_c
     F     }       #repeat B times
      N¹è          #push the Nth char of A
         '(        #push '('
            X      #push X
             ®')×  #push ')' repeated B times
                 J #join together
                   #implicit print
```
[Answer]
# Vim, 17 bytes
`$qqha(<Esc>A)<Esc>%h@qq@q`
Goes from end to beginning, because otherwise you trip over the `)`s you've already written. Uses `ha` instead of `i` to fail when it reaches the beginning.
Usually, you wouldn't do two separate inserts like this; you'd do something like `C()<Esc>P` to save a stroke. But the positioning doesn't work as well this time.
[Answer]
## [Jellyfish](https://github.com/iatorm/jellyfish), ~~19~~ 18 bytes
```
P
,+>`
_  {I
/'␁'(
```
The character `␁` is the unprintable control character with byte value `0x1`. [Try it online!](http://jellyfish.tryitonline.net/#code=UAosKz5gCl8gIHtJCi8nASco&input=SGkh)
## Explanation
This is a pretty complex Jellyfish program, since many values are used in multiple places.
* `I` is raw input, read from STDIN as a string.
* `'(` is the character literal `(`.
* The `{` (left identity) takes `'(` and `I` as inputs, and returns `'(`.
The return value is never actually used.
* ``` is thread. It modifies `{` to return the character `(` for each character of `I`, resulting in a string of `(`s with the same length as `I`.
* `>` is tail; it takes the string of `(`s as input and chops off the first character.
* `+` takes as arguments the string of `(`s and the unprintable byte, and adds the byte value (1) to each character. This gives an equal-length string of `)`s.
Using the character `␁` guarantees that the return value is a string, and not a list of integers.
* On the lower left corner, `/` takes the unprintable byte, and returns a *function* that takes two arguments, and joins the second argument with the first one once (since the byte value is 1).
* `_` takes this function, grabs the arguments of the lower `{` (which were `'(` and `I`), and calls the funtion with them. This inserts the character `(` between every pair of characters in `I`.
* `,` concatenates this string with the string of `)`s, and `P` prints the result.
[Answer]
# [Convex](http://github.com/GamrCorps/Convex), 10 bytes
```
_'(*\,(')*
```
[Try it online!](http://convex.tryitonline.net/#code=XycoKlwsKCcpKg&input=&args=SGVsbG8)
[Answer]
# [><>](http://esolangs.org/wiki/Fish), 37 bytes
```
i:0(?\'('
$,2l~/~
/?(2:<-1$')'
>~ror:
```
**Row by row**
1. Pushes each char from input with an opening parenthesis after each
2. Removes EOF and the last opening parenthesis and pushes the stack length
3. Uses a comparison with half the stack length to push the closing parenthesis
4. Prints the content of the stack
[Try it online!](http://fish.tryitonline.net/#code=aTowKD9cJygnCiQsMmx-L34KLz8oMjo8LTEkJyknCj5-cm9yOg&input=SGVsbG8gV29ybGQh)
[Answer]
# Perl, 36 bytes (34 + 2 for `-lp`flag)
Thanks to Dada for pointing out a bug and saving one byte (in total)!
Splits the string into an array, then joins it with the `(`delimiter. We directly add the closing `)`since `length`returns the length of the string before the `join`.
```
$_=(join"(",split//).")"x(y///c-1)
```
[Try it here!](http://ideone.com/NyBniB)
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak) 103 97 Bytes
Includes +3 for -c
```
{({}<><(((((()()){}()){}){}){})>)<>}<>({}<([][()]){({}[()()]<(({})()<>)<>>)}{}>){({}<>)<>}<>{}
```
[Try it Online!](http://brain-flak.tryitonline.net/#code=eyh7fTw-PCgoKCgoKCkoKSl7fSgpKXt9KXt9KXt9KT4pPD59PD4oe308KFtdWygpXSl7KHt9WygpKCldPCgoe30pKCk8Pik8Pj4pfXt9Pil7KHt9PD4pPD59PD57fQ&input=Y29kZS1nb2xm&args=LWM)
---
**Explanation:**
```
#reverse the stack and put a 40 between every number
{({}<><(((((()()){}()){}){}){})>)<>}<>
{                                  }   #repeat this until the stack is empty
 ({}                            )      #pop the top and push it after
    <>                                 #switching stacks and
      <(((((()()){}()){}){}){})>       #pushing a 40 (evaluated as 0) 
                                 <>    #switch back to the first stack
                                    <> #switch to the stack that everything is on now    
#put as many )s on the other stack as needed
({}                                      ) #pop the top letter and put it  back
                                           #after doing the following
                                           #This leaves ( on the top
   <                                    >  #evalute this part as 0
    ([][()])                               #push the height of the stack minus one
            {                        }    #repeat until the "height" is 0
             ({}[()()]              )     #pop the "height" and push is minus two
                      <            >      #evaluate to 0
                       (        )         #push:
                        ({})              #the top of the stack (putting it back on)
                            ()            #plus one onto
                              <>          #the other stack
                                 <>       #switch back to the other stack
                                      {}  #pop what was the height of the stack
#move the string of letters and (s back, reversing the order again
{        }     # repeat until all elements are moved
 (    )        # push:
  {}           # the top of the stack after
    <>         # switching stacks
       <>      # switch back to the other stack
          <>   # switch to the stack with the final string
            {} #pop the extra (
```
]