2

i am preparing for my finals and came across this question:

Learn about the reflection mechanisms of Java, C# and Prolog, all of which allow a program to inspect and reason about its own symbol table at run time. How complete are these mechanisms? (For example, can a program inspect symbols that aren’t currently in scope?) What is reflection good for? What uses should be considered good or bad programming practice?

Why is this question asked in terms of symbol table? Can i write the same solution that i write in terms of classes and objects like mentioned in this SO question:

What is reflection and why is it useful?

Community
  • 1
  • 1
Justin Carrey
  • 3,563
  • 8
  • 32
  • 45
  • 3
    Maybe ask your tutor why it is phrased that way? – Marc Gravell Dec 16 '13 at 09:35
  • 2
    When it comes to assignment and exams, the most important thing it to come up with the **expected** answer, not just any answer which appears correct in the outside world. In this case, having an answer is better than none, but you really need to know what the marker would expect of you based on your course. – Peter Lawrey Dec 16 '13 at 09:40

3 Answers3

1

I'd suggest you to read the following pages to get an idea of reflection in the corresponding language:

After Reading those you shold see similarities of the methods. To be honest, I've never worked with reflection in Prolog, but the docs should guide you through.

The symobl table is used by the reflection mechanisms to look the things up. See here for a description of symbol tables.

Those resources should give you an idea on how to answer your questions

user229044
  • 232,980
  • 40
  • 330
  • 338
sternze
  • 1,524
  • 2
  • 9
  • 15
1

The "symbol table" is just an internal concept that is needed for "reflection" to do what it does: the ability of a program to examine itself at runtime and do something dynamically with that. (be aware about the diff between - introspection vs. reflection).

So if you understand what reflection is good for, how it is implemented in your target platform (Java, C# etc.), and what might be the limitations, you should be able to answer all those questions I suppose.

Think about the symbol table as just an "implementation detail" of a platform/runtime. According to the question above I don't think they expect you to know exactly how this is implemented.

Florian
  • 271
  • 3
  • 14
  • [introspection vs. reflection](http://stackoverflow.com/questions/351577/why-is-reflection-called-reflection-instead-of-introspection) - TL;DR Read vs Read/Write access – zapl Dec 16 '13 at 10:00
1

I think of reflection as the basic tool to do metaprogramming.

This turns out to be a declarative way to solve (a kind of) problems. Sometime, instead of building a solution, can be useful to write something that allow to describe the problem space. That is, see if your problem can be restated in a more practical language.

You see, we treat languages as components of algorithms, like data. Then we can exchange components between languages.

Practically, an example of interesting Java/Prolog reflection is JPL

Some time ago I found useful - and performant - C# reflection. United to emit package allows to produce compiled code.

Prolog use reflection in seamless ways: for instance DCGs are really a 'simple' rewrite of declared rules.

I've started a project that I hope I will take me to Prolog controlling Qt interface, of course Qt reflection plays a fundamental role.

edit About your question on symbol tables: symbol is an extremely general term. Also all languages have a concept of symbols, (maybe) differently aggregated. That's the core of languages. Then the question is perfectly posed in very general terms, just to check your understanding of these basic language concepts.

CapelliC
  • 59,646
  • 5
  • 47
  • 90