[Question]
  [
You must produce a function which nests a string `s` inside an array, `n` times
```
>>> N("stackoverflow",2)
[['stackoverflow']]
```
# Parameters:
1. `s` - An ascii string
2. `n` - An integer `>= 0`
## Rules
* Shortest code wins.
* The output will be a nested `array`, `list` or `tuple` (or similar type based off an array)
## Test Cases
```
>>> N("stackoverflow",0)
'stackoverflow'
>>> N("stackoverflow",1)
['stackoverflow']
>>> N("stackoverflow",5)
[[[[['stackoverflow']]]]]
```
---
Inspired by: [Nesting a string inside a list n times ie list of a list of a list](https://stackoverflow.com/questions/40083007/nesting-a-string-inside-a-list-n-times-ie-list-of-a-list-of-a-list#40083670)
  
[Answer]
# Java and C#, 62 bytes
```
Object f(String s,int n){return n<1?s:new Object[]{f(s,n-1)};}
```
Should work without modification in both Java and C#.
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 3 bytes
**Code**
```
`F)
```
**Explanation**
```
`   # Flatten the input array on the stack.
 F  # Element_2 times do:
  ) # Wrap the total stack into a single array.
```
This means that this also works for the **0**-testcase, since the string is already on the stack.
[Try it online!](http://05ab1e.tryitonline.net/#code=YEYp&input=WyJzdGFja292ZXJmbG93IiwgNV0)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
W¡
```
Slightly confusing, since: (1) Jelly has no strings, only lists of characters; and (2); the output wont show the nesting. To see that this actually is doing what is asked look at a Python string representation of the result with:
```
W¡ŒṘ
```
An extra pair of `[]` will be present since the string itself will be a list of characters. [For example](http://jelly.tryitonline.net/#code=V8KhxZLhuZg&input=&args=InN0YWNrb3ZlcmZsb3ci+NQ)
### How?
```
W¡ - Main link: s, n
W  - wrap left, initially s, in a list
 ¡ - repeat previous link n times
```
The proof-of-concept code adds:
```
W¡ŒṘ - Main link: s, n
  ŒṘ - Python string representation
```
[Answer]
## JavaScript (ES6), 20 bytes
```
d=>g=n=>n--?[g(n)]:d
```
Although people normally nag me to curry my functions for the 1-byte saving, this is a case where it actually contributes to the solution.
[Answer]
## Mathematica, 13 bytes
```
List~Nest~##&
```
[Answer]
# [CJam](//sourceforge.net/projects/cjam), ~~7~~ 6 bytes
```
{{a}*}
```
[Online interpreter](//cjam.aditsu.net#code=r%7E%7E%7Ba%7D*&input=%5B%22stackoverflow%225%5D)
This is an unnamed function that takes its arguments from the stack as `S N`, `S` being the string and `N` being the wraps. You can execute it with the `~` operator, meaning eval.
Explanation:
```
{{a}*}
{      Open block    [A B]
 {     Open block    [A]
  a    Wrap in array [[A]]
   }   Close block   [A B λwrap]
    *  Repeat        [A:wrap(*B)]
     } Close block   ["S" N λ(λwrap)repeat]
```
[Answer]
# Javascript ES6, 23 bytes
Recursive function
```
f=(a,i)=>i?f([a],--i):a
console.log(f("stackoverflow",0))
console.log(f("stackoverflow",1))
console.log(f("stackoverflow",2))
console.log(f("stackoverflow",5))
```
Currying results in the same length
```
f=a=>i=>i?f([a])(--i):a
```
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 10 bytes
```
tT,?h:T:gi
```
[Try it online!](http://brachylog.tryitonline.net/#code=dFQsP2g6VDpnaQ&input=WyJzdGFjayBvdmVyZmxvdyI6NV0&args=Wg)
### Explanation
```
tT,            T is the integer (second element of the Input)
   ?h:T:g      The list [String, T, built-in_group]
         i     Iterate: Apply built-in_group T times to String
```
This would be 3 bytes if it wasn't bugged. Here we need all this to get the list `[String, T, built-in_group]` even though `[String, T]` is already our input.
Unfortunately `:g` directly results in `[[String, T], built-in_group]`, which is not recognized properly by `i` because the integer `T` is inside the first list.
[Answer]
# MATL, 6 bytes
```
ji:"Xh
```
This produces a nested cell array as the output. With MATL's default display, however, you can't necessary *see* that's what it is since it won't show all of the curly braces. The demo below is a slightly modified version which shows the string representation of the output.
```
ji:"Xh]&D
```
[**Try it Online**](http://matl.tryitonline.net/#code=amk6IlhoXSZE&input=c3RhY2tvdmVyZmxvdwo1)
**Explanation**
```
j       % Explicitly grab the first input as a string
i       % Explicitly grab the second input as an integer (n)
:"      % Create an array [1...n] and loop through it
    Xh  % Each time through the loop place the entire stack into a cell array
        % Implicit end of for loop and display
```
[Answer]
## Pyke, 3 bytes
```
V]1
```
[Try it here!](http://pyke.catbus.co.uk/?code=V%5D1&input=4%0Astackoverflow)
[Answer]
# Python, 32 bytes
```
N=lambda s,n:n and[N(s,n-1)]or s
```
[Answer]
# [Pyth](//github.com/isaacg1/pyth), 3 bytes
```
]Fw
```
[Permalink](//pyth.herokuapp.com?code=%60%5DFw&input=4%0A3&test_suite=1&test_suite_input=0%0Astackoverflow%0A1%0Astackoverflow%0A5%0Astackoverflow&input_size=2)
This will output something like `...[[[[['string']]]]]...`. It will not quote for zero depth: `string`.
Explanation:
```
]Fw
   Q Implicit: Eval first input line
]    Function: Wrap in array
  w  Input line
 F   Apply multiple times
```
If you want quoting on zero depth, use this 4-byte solution instead (explanation):
```
`]Fw
    Q Implicit: Eval first input line
 ]    Function: Wrap in array
   w  Input line
  F   Apply multiple times
`     Representation
```
[Answer]
# PHP, 60 Bytes
```
for($r=$argv[1];$i++<$argv[2];)$r=[$r];echo json_encode($r);
```
48 Bytes if it looks only like the task
```
for($r=$argv[1];$i++<$argv[2];)$r="[$r]";echo$r;
```
[Answer]
# Ruby: 23 bytes
```
->n,s{n.times{s=[s]};s}
```
This is updated to make it a callable Proc rather than the original snippet. I'd be interested to know whether there's a way to have `s` implicitly returned rather than having to explicitly return it.
[Answer]
## C, ~~44 bytes~~, 41 bytes
```
int*n(int*s,int a){return a?n(&s,a-1):s;}
```
You can test it by doing the following:
```
int main(void) {
    char* s = "stackoverflow";
    /* Test Case 0 */
    int* a = n(s,0);
    printf("'%s'\n", a);
    /* Test Case 1 */
    int* b = n(s,1);
    printf("['%s']\n", *b);
    /* Test Case 2 */
    int** c = n(s,2);
    printf("[['%s']]\n", **c);
    /* Test Case 3 */
    int*** d = n(s,3);
    printf("[[['%s']]]\n", ***d);
    /* Test Case 4 */
    int********** e = n(s,10);
    printf("[[[[[[[[[['%s']]]]]]]]]]\n", **********e);
    return 0;
}
```
The output:
```
'stackoverflow'
['stackoverflow']
[['stackoverflow']]
[[['stackoverflow']]]
[[[[[[[[[['stackoverflow']]]]]]]]]]
```
Of course, you'll get warnings. This works on `gcc` on bash on my Windows machine (`gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)`, as well as on a true Linux machine (`gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)`).
[Answer]
# k, 3 bytes
```
,:/
```
Taken as a dyadic function, `/` will iteratively apply the left-hand function `,:` (`enlist`) n times to the second argument.
Example:
```
k),:/[3;"hello"]
,,,"hello"
```
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$ 5 \log\_{256}(96) \approx \$ 4.12 bytes
```
s{KZO
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhZLi6u9o_whbKjQgvXFJYnJ2fllqUVpOfnlXKYQYQA)
If the inputs could be taken in any order, the leading `s` could be dropped.
#### Explanation
```
s{KZO  # Implicit input
s      # Swap so the number is on top
 {K    # Loop input number of times:
   ZO  # Wrap in a list
       # Implicit output
```
[Answer]
# Ruby, 25 characters
Rewrite of [jamylak](https://codegolf.stackexchange.com/users/4094/jamylak)'s [Python solution](https://codegolf.stackexchange.com/a/96488).
```
f=->s,n{n>0?[f[s,n-1]]:s}
```
Sample run:
```
irb(main):001:0> f=->s,n{n>0?[f[s,n-1]]:s}
=> #<Proc:0x00000002006e80@(irb):1 (lambda)>
irb(main):002:0> f["stackoverflow",0]
=> "stackoverflow"
irb(main):003:0> f["stackoverflow",1]
=> ["stackoverflow"]
irb(main):004:0> f["stackoverflow",5]
=> [[[[["stackoverflow"]]]]]
```
[Answer]
## C# 6, 50 bytes
```
dynamic a(dynamic s,int n)=>n<2?s:a(new[]{s},n-1);
```
[Answer]
# Ruby, 24 bytes
```
f=->*s,n{s[n]||f[s,n-1]}
```
Called the same as in [manatwork's answer](https://codegolf.stackexchange.com/a/96491/6828), but a weirder implementation. `*s` wraps the input (a possibly-nested string) in an array. Then if `n` is zero, `s[n]` returns the first element of `s`, turning the function into a no-op. Otherwise, it returns `nil` since `s` will only ever have one element, so we pass through to the recursive call.
[Answer]
# [V](http://github.com/DJMcMayhem/V), 6 bytes
```
Àñys$]
```
[Try it online!](http://v.tryitonline.net/#code=w4DDsXlzJF0&input=J0hlbGxvLCB3b3JsZCEi&args=NA)
Explanation:
```
À      "Arg1 times
 ñ     "repeat:
  ys$  "surround this line
     ] "with square brackets
```
[Answer]
# [Perl 6](https://perl6.org), 23 bytes
```
{($^a,{[$_]}...*)[$^b]}
```
## Expanded:
```
{ # bare block lambda with two placeholder parameters ｢$a｣ and ｢$b｣
  (
    # generate Sequence
    $^a,       # declare first input
    { [ $_ ] } # lambda that adds one array layer
    ...        # do that until
    *          # Whatever
  )[ $^b ]     # index into the sequence
}
```
[Answer]
## Agda, 173 bytes
Since the return type of the function depends on the number given as argument, this is clearly a case where a dependently typed language should be used. Unfortunately, golfing isn't easy in a language where you have to import naturals and lists to use them. On the plus side, they use `suc` where I would have expected the verbose `succ`. So here is my code:
```
module l where
open import Data.List
open import Data.Nat
L : ℕ -> Set -> Set
L 0 a = a
L(suc n)a = List(L n a)
f : ∀ n{a}-> a -> L n a
f 0 x = x
f(suc n)x = [ f n x ]
```
(I hope I found all places where spaces can be omitted.) `L` is a type function that given a natural `n` and a type `a` returns the type of `n` times nested lists of `a`, so `L 3 Bool` would be the type of lists of lists of lists of `Bool` (if we had imported `Bool`). This allows us to express the type of our function as `(n : ℕ) -> {a : Set} -> a -> L n a`, where the curly braces make that argument implicit. The code uses a shorter way to write this type. The function can now be defined in an obvious way by pattern matching on the first argument.
Loading this file with an `.agda` extension into emacs allows to use `C-c C-n` (evaluate term to normal form), input for example `f 2 3` and get the correct answer in an awkward form: `(3 ∷ []) ∷ []`. Now of course if you want to do that with strings you have to import them...
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
@[X]}gNÅ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=QFtYXX1nTsU&input=OAoiSmFwdCIKLVE)
[Answer]
## [Jellyfish](http://github.com/iatorm/jellyfish), 8 bytes
```
p\Ai
 ;i
```
[Try it online!](http://jellyfish.tryitonline.net/#code=cFxBaQogO2k&input=NAoidGVzdCI)
Unary `;` wraps its argument in a list. Binary `\` on a function and a value `n` iterates that function `n` times.
[Answer]
# PHP, 44 bytes
```
function n($s,$n){return$n?n([$s],--$n):$s;}
```
nothing sophisticated, just a recursive function
[Answer]
## Python 2, 32 bytes
```
lambda s,n:eval('['*n+`s`+']'*n)
```
Puts `n` open brackets before the string and `n` close brackets before it, then evals the result. If a string output is allowed, the `eval` can be removed.
[Answer]
# [Actually](http://github.com/Mego/Seriously), 4 bytes
Input is `string` then `n`. Golfing suggestions welcome. [Try it online!](http://actually.tryitonline.net/#code=YGtgbg&input=InN0YWNrb3ZlcmZsb3ciCjU)
```
`k`n
```
**Ungolfing**
```
          Implicit input string, then n.
`...`n    Run the function n times.
  k         Wrap the stack in a list.
          Implicit return.
```
[Answer]
## R, 39 40 bytes
EDIT: Fixed the `n=0` issue thanks to @rturnbull.
Function that takes two inputs `s` (string) and `n` (nestedness) and outputs the nested list. Note that R-class `list` natively prints output differently than most other languages, however, is functionally similar to a key/value map (with possibly unnamed keys) or a list in python.
```
f=function(s,n)if(n)list(f(s,n-1))else s
```
**Example**
```
> f=function(s,n)if(n)list(f(s,n-1))else s
> f("hello",3)
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] "hello"
> # to access the string nested 5 times in the "list-object" named "list" we can do the following
> list = f("nested string",5)
> list[[1]][[1]][[1]][[1]][[1]]
[1] "nested string"
```
[Answer]
## Racket 83 bytes
```
(for((c n))(set! s(apply string-append(if(= c 0)(list"[\'"s"\']")(list"["s"]")))))s
```
Ungolfed: 
```
(define (f s n)
  (for ((c n))
    (set! s (apply string-append
                   (if (= c 0)
                       (list "[\'" s "\']")
                       (list "[" s "]"))
                   )))
  s)
```
Testing: 
```
(f "test" 3)
```
Output:
```
"[[['test']]]"
```
]