5

Basically question says it all.

When I declare a function signature in gen-class, what type do I put for a 2D array of strings?

[myFunc [XXXX] ReturnType]

what do I put for XXXX?

Update : following @Mark Topolnik's suggestion, I'm trying

#^{:static true} [myFunc [ ^"[[Ljava.lang.String;" ] clojure.lang.IFn] 

in my declaration, and I'm getting back a

java.lang.RuntimeException: Unmatched delimiter: ]

runtime exception when I try to compile it.

Update 2 : Fixed by removing the ^ from the above line. (This is in the context of declaring function signatures in a gen-class so that ^ is presumably unnecessary.)

interstar
  • 26,048
  • 36
  • 112
  • 180
  • 1
    Related: http://stackoverflow.com/questions/3779876/how-to-type-hint. So I guess `^"[[Ljava.lang.String" strings` would be the only (ugly) way. – Marko Topolnik Dec 01 '14 at 14:59
  • Isn't that a single dimension of array? – interstar Dec 01 '14 at 15:15
  • 1
    The number of initial open-brackets specifies the depth of the array. – Marko Topolnik Dec 01 '14 at 15:16
  • Ah ... that's something I didn't pick up on. I always thought it was the L that meant List or something that made it an array. What does the L mean then? – interstar Dec 01 '14 at 15:19
  • 1
    Who knows what `L` stands for as a mnemonic, but it means "reference type" and requires the fully-qualified name of the type to follow, ending with `;` (I forgot that one in my comment). – Marko Topolnik Dec 01 '14 at 15:22
  • Actually, when I try it I'm getting an unmatched delimiter exception (updated the question) – interstar Dec 01 '14 at 15:40
  • But you didn't name your variable. The type hint metadata must refer to *something*. – Marko Topolnik Dec 01 '14 at 16:19
  • Ah ... I fixed it. Didn't need the ^ in this context (it's a function declaration in a class-gen). Sorry. I'm still a bit hazy on the sigils in Clojure. – interstar Dec 01 '14 at 16:36
  • 1
    @MarkoTopolnik, it looks like you answered the question in the comments. Shouldn't you record it as an official answer, so that interstar can accept it? – Mars Dec 02 '14 at 05:24
  • Agree with Mars @MarkoTopolnik . Make it an answer and I'll accept it. – interstar Dec 02 '14 at 17:24

1 Answers1

3

Multidimensional array types have no direct support in Clojure, but you can always fall back to using a String with the binary type name. In your case, this would look like the following:

[myFunc ["[[Ljava.lang.String;"] ReturnType]
Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436