Reflection

54 views
Skip to first unread message

Anton Lobach

unread,
May 26, 2019, 11:37:17 AM5/26/19
to ParaSail Programming Language
Hi Tucker,

I have several questions regarding reflections.

1. Is it possible to make a reflection library for ParaSail similar in capabilities (including metaprogramming) to Scala's library?
2. In general, does this require adding extensions to the language?

I know that there is a reflection library in the lib directory but I am not sure if it is just the compiler's internals.

Best,
Anton

Tucker Taft

unread,
May 26, 2019, 11:54:12 AM5/26/19
to ParaSail Programming Language
The lib/reflection.psi was created to support the compiler, but could be extended further.  I don't foresee the need to extend the syntax of the language to support more reflection, but it would be helpful to know which particular reflection capabilities were of most interest.  Can you give some examples of use that are of interest to you?

Take care,
-Tuck

--
You received this message because you are subscribed to the Google Groups "ParaSail Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to parasail-programming...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/parasail-programming-language/58a2d220-2185-48bd-a136-2f6425013d42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anton Lobach

unread,
May 26, 2019, 11:33:54 PM5/26/19
to parasail-progr...@googlegroups.com
Unfortunately, I do not have a detailed example yet but some high level ideas. For example, I am thinking about an automatic differentiation library, so, at a high level it would look roughly like the following. A user supplies an expression to the function, say, Differentiate (Expression => Y * (X**2), With_Respect_To => X) and then the Differentiate function would transform the input into 2 * Y * X that can be evaluated at some X and Y. So, basically, Differentiate takes an expression and returns a modified (according to differentiation rules) expression. It looks like this use case is similar in spirit to this reflective Ada approach and falls under the definition of reflection given here (Scala's reflection library) that a program can inspect and modify itself.

So, I guess, to achieve such functionality I need an access to the expression's AST for inspection and modification and my understanding is that a reflection library should allow me to do that. 

Best,
Anton


For more options, visit https://groups.google.com/d/optout.


--
Regards,

Anton Lobach

Tucker Taft

unread,
May 27, 2019, 11:31:42 AM5/27/19
to ParaSail Programming Language
The current reflection capability provides access to the PSVM (ParaSail Virtual Machine) representation of the program, which is probably not what you are looking for.  Because you can overload all operators in ParaSail, another approach is to define a type or set of types that create an AST as a result of evaluation, and then you can define additional operations to do things like derivation and integration.  A simple illustration of this approach is included in the examples subdirectory, called "expr_tree.psl".  We'll look into providing access to a more complete reflection library.  Another alternative might be to provide a library for parsing ParaSail constructs.

Take care,
-Tuck

Vratislav Podzimek

unread,
May 28, 2019, 4:22:42 AM5/28/19
to ParaSail Programming Language
Something like libadalang would be amazing.

-- Vratislav

Anton Lobach

unread,
Jul 22, 2019, 9:28:34 PM7/22/19
to ParaSail Programming Language

I guess, an access to the PSVM instructions might work as well.
Thank you for pointing to the "expr_tree.psl" it looks similar to what I am trying to achieve.
By "a library for parsing ParaSail constructs" do you mean an external tool that will process a file with a source code and output a modified source code or a library that will be able to parse constructs from within like in Julia?
There is another paper about reflection in Ada that I thought might interest you.

Best,
Anton


The current reflection capability provides access to the PSVM (ParaSail Virtual Machine) representation of the program, which is probably not what you are looking for.  Because you can overload all operators in ParaSail, another approach is to define a type or set of types that create an AST as a result of evaluation, and then you can define additional operations to do things like derivation and integration.  A simple illustration of this approach is included in the examples subdirectory, called "expr_tree.psl".  We'll look into providing access to a more complete reflection library.  Another alternative might be to provide a library for parsing ParaSail constructs.

Take care,
-Tuck

On Sun, May 26, 2019 at 11:33 PM Anton Lobach <anton...@uri.edu> wrote:
Unfortunately, I do not have a detailed example yet but some high level ideas. For example, I am thinking about an automatic differentiation library, so, at a high level it would look roughly like the following. A user supplies an expression to the function, say, Differentiate (Expression => Y * (X**2), With_Respect_To => X) and then the Differentiate function would transform the input into 2 * Y * X that can be evaluated at some X and Y. So, basically, Differentiate takes an expression and returns a modified (according to differentiation rules) expression. It looks like this use case is similar in spirit to this reflective Ada approach and falls under the definition of reflection given here (Scala's reflection library) that a program can inspect and modify itself.

So, I guess, to achieve such functionality I need an access to the expression's AST for inspection and modification and my understanding is that a reflection library should allow me to do that. 

Best,
Anton

On Sun, May 26, 2019 at 11:54 AM Tucker Taft <tuc...@yaletaft.com> wrote:
The lib/reflection.psi was created to support the compiler, but could be extended further.  I don't foresee the need to extend the syntax of the language to support more reflection, but it would be helpful to know which particular reflection capabilities were of most interest.  Can you give some examples of use that are of interest to you?

Take care,
-Tuck

On Sun, May 26, 2019 at 11:37 AM Anton Lobach <entru...@gmail.com> wrote:
Hi Tucker,

I have several questions regarding reflections.

1. Is it possible to make a reflection library for ParaSail similar in capabilities (including metaprogramming) to Scala's library?
2. In general, does this require adding extensions to the language?

I know that there is a reflection library in the lib directory but I am not sure if it is just the compiler's internals.

Best,
Anton

--
You received this message because you are subscribed to the Google Groups "ParaSail Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to parasail-programming-language+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ParaSail Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to parasail-programming-language+unsub...@googlegroups.com.


--
Regards,

Anton Lobach

--
You received this message because you are subscribed to the Google Groups "ParaSail Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to parasail-programming-language+unsub...@googlegroups.com.

Tucker Taft

unread,
Jul 22, 2019, 10:25:34 PM7/22/19
to ParaSail Programming Language
On Mon, Jul 22, 2019 at 9:28 PM Anton Lobach <anton...@uri.edu> wrote:

I guess, an access to the PSVM instructions might work as well.
Thank you for pointing to the "expr_tree.psl" it looks similar to what I am trying to achieve.
By "a library for parsing ParaSail constructs" do you mean an external tool that will process a file with a source code and output a modified source code or a library that will be able to parse constructs from within like in Julia?

The existing reflection library gives access to some amount of the representation of the program that has been read in by the front end of the interpreter, but it could be beefed up.  As indicated, it mostly focuses on the PSVM representation, but it could be extended to provide access to some of the abstract syntax tree and associated semantic info.  This same library could be used by a stand-alone tool.  As an example, the ParaScope static analysis tool is linked with the parser and semantic analysis code from the interpreter, and then does further analysis to try to find bugs.  ParaScope is written in ParaSail itself, but is linked using the code of the ParaSail interpreter effectively as a library.  When ParaScope is invoked, the user specifies the source files of interest on the command line, and ParaScope ignores source files not specified, which might include its own code when running ParaScope itself in the interpreter.  (Talking about reflection can be confusing!)

One feature of the ParaSail compiler is that any expression that takes no external input is automatically fully evaluated at compile time.  This means that you could write a program that incorporates a parser builder like YACC, and which builds the parse tables at compile time given the BNF for the grammar as a big String.  You could imagine more interesting ways to use the interpreter during compilation as well.  One thing I don't love about some metaprogramming models is that they require the programmer to learn essentially another language, the metaprogramming language.  In ParaSail, you are always just writing in ParaSail, yet you still have the full power of the language at compile time.

There is another paper about reflection in Ada that I thought might interest you.

Thanks.  I have known both of the authors quite well for years (one works at AdaCore), but I hadn't seen this paper until just recently.

In any case, there are clearly lots of things that could be done.  What is probably needed is a "killer app" for reflection, to know what new features are worth investing in first.


Best,
Anton

Take care,
-Tuck

...
Reply all
Reply to author
Forward
0 new messages