On Wed, Nov 19, 2008 at 10:52 AM, Ralf Hemmecke wrote:
>
> do you actually see a need for reflection? The only things that come
> to my mind are a debugger written in SPAD and perhaps some more
> convenience for unit testing (But for the latter I find reflection not
> terribly necessary.) I debugger is a rather low-level thing, so a
> special (not-exported) language feature to implement it is certainly
> helpful. Any other things that you have in mind when it comes to the
> implementation of a Mathematics library?
>
I do not see any immediate need for reflection (self description) in a
mathematical library since in most cases one starts with the
assumption that one knows the domains of objects with which we are
dealing. This is what makes efficienct compilation possible.
Programmers might use reflection in order to avoid having to consider
the most general cases. Look at the following code in
'src/algebra/numsolve.spad.pamphlet':
...
InnerNumericFloatSolvePackage(K,F,Par): Cat == Cap where
F : Field -- this is the field where the answer will be
K : GcdDomain -- type of the input
Par : Join(Field, OrderedRing ) -- it will be NF or RN
I ==> Integer
NNI ==> NonNegativeInteger
P ==> Polynomial
EQ ==> Equation
L ==> List
SUP ==> SparseUnivariatePolynomial
RN ==> Fraction Integer
NF ==> Float
CF ==> Complex Float
GI ==> Complex Integer
GRN ==> Complex RN
SE ==> Symbol
RFI ==> Fraction P I
Cat == with
...
Cap == add
...
numeric(r:K):F ==
K is I =>
F is Float => r::I::Float
F is RN => r::I::RN
F is CF => r::I::CF
F is GRN => r::I::GRN
K is GI =>
gr:GI := r::GI
F is GRN => complex(real(gr)::RN,imag(gr)::RN)$GRN
F is CF => convert(gr)
error "case not handled"
----
Surely the function 'numeric' could have been written without these
cases with just a l little more thought.
> Note... I don't speak about the interpreter. Runtime reflection in the
> interpreter may be wanted for several reasons. If I sit in front of my
> CAS, I'd like to be able to ask what functions a certain domain exports.
> A user cannot be expected to have the source code lying somewhere
> on his/her hard drive.
>
> However, I consider interpreter and library design as two different
> things. So what use cases in library design do you see?
>
There are cases where this separation between the interpreter and the
library might not be completely natural. For example reflection may be
useful is when one is specifically trying to avoid (at least
temporarily) the issue of typing - so called "duck typing". The domain
'Any' in the Axiom library is a good example of this. If Spad had more
features relating to reflection then it would be possible to implement
'Any' without resorting to low level Lisp calls and unsafe operations
like "pretend". But even then, there are other language features that
would make reflection unnecessary. In the case of 'Any' improving
Spad's handling of Union and subdomains would make it possible to
define 'Any' as an indefinite union of domains:
Union(x for x in Domain)
So my conclusion in the end is that the use of reflection is (almost
always) undesirable and usually indicates the presence of some other
deficiency in the language.
Regards,
Bill Page.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---