Macro ideas from other projects

63 views
Skip to first unread message

Baldur Norddahl

unread,
Jan 17, 2013, 6:57:56 PM1/17/13
to sca...@googlegroups.com
Hello everyone,

I am using Scalate Jade with Play 2.1 and a database engine called Sqltyped: https://github.com/jonifreeman/sqltyped

Play has a system that allows compile time type safe templates. Type safe is nice but it is done with cumbersome code generation.

Sqltyped uses the new Scala 2.10 macro facility to do something like it but without code generation.

Using macros Scalate could check that the template exists, that the template compiles and that the parameters passed matches what is expected by the template.

Like Sqltyped, we could have code like:

val myTemplate = jade("templates/myTemplate.jade")
val htmlResponse = myTemplate(parm1,parm2)

Where the jade() method is a macro that returns a function of the correct arity and parameter types.

What are your thoughts on such an extension to Scalate?

Regards,

Baldur

Rafał Krzewski

unread,
Feb 3, 2013, 6:57:02 AM2/3/13
to sca...@googlegroups.com
That's a cool idea. I'm sure people using Scalate as embedded component for general purpose text-generation would enjoy that!
If you manage to get this working, please share :)

Cheers,
Rafał

Ross A. Baker

unread,
Feb 7, 2013, 4:27:57 PM2/7/13
to sca...@googlegroups.com
Some ignorant ramblings from someone who's played a little with macros:

All we have now are def macros, where the def must declare a return
type, and the macro must match its "shape." I don't see how the
proposed jade method could return different arities. I think this
could be a fantastic use case for type macros, which are currently
implemented in Macro Paradise:
http://docs.scala-lang.org/overviews/macros/typemacros.html. It's a
wonderful idea if and when the language supports it.

I suspect the validation and precompilation features could work in
Scala 2.10, but only if passed a string literal.
> --
> You received this message because you are subscribed to the Google Groups
> "Scalate" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalate+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Ross A. Baker
ba...@alumni.indiana.edu
Indianapolis, IN, USA

Baldur Norddahl

unread,
Mar 2, 2013, 9:51:05 AM3/2/13
to sca...@googlegroups.com
I think Sqltyped already shows how to do this. You do not need macro types. Macro types is the ability to create new types but in this case the types already exists in the form of Function1 ... Function22.

All you need is a generic macro function:

def jade[T](template: String): T

T will then be inferred to the correct type at compile time.

Regards,

Baldur
Reply all
Reply to author
Forward
0 new messages