For some reason I read the word "macro" in your question, but maybe that's what happens when you've been doing Scala 3 macros all day...
-
-
Replying to @propensive @skaalf
I don't know of one, though. But the macro is very easy. Something like this: def unpack[T <: Singleton & String: Type](using Quotes): Expr[List[Char]] = import quotes.reflect._ TypeRepr.of[T] match case ConstantType(StringConstant(str)) => '{ str.toList } (untested) ;)
1 reply 0 retweets 2 likes -
Replying to @propensive @skaalf
Oh, and you'll also need the macro inline def unpack[T <: Singleton & String]: List[Char] = ${unpack[T]}
1 reply 0 retweets 0 likes -
Replying to @propensive
"access to value str from wrong staging level:" ^^
1 reply 0 retweets 0 likes -
Replying to @skaalf
Ah, you need to do `str.value.toList` outside the `'{}` and then put it inside.
2 replies 0 retweets 0 likes -
-
Replying to @skaalf
That's because I keep trying to guess at the answer without actually trying it. ;) Give me a moment...!
2 replies 0 retweets 0 likes -
Replying to @propensive
I tried: private def unpackImpl[S <: Singleton & String: Type](using q: Quotes): Expr[Any] = import q.reflect._ TypeRepr.of[S] match case ConstantType(StringConstant(str)) => '{ Tuple.fromArray(${Expr(str.toArray)}) } Which gives: Cyclic macro dependencies
1 reply 0 retweets 0 likes -
Replying to @skaalf
The cyclic dependencies could be because you're trying to use the macro in the same file it's defined in.
1 reply 0 retweets 0 likes -
I think you might need to use separate files.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.