Thanks Raul.
To get started, I want a verb that takes a string and creates a class and
an instance out of it.
Example:
c =: create 'customer'
Must result in a class definition like so :
coclass 'customer' NB. Gets executed
create=: cocreate NB. Gets executed
destroy =: codestroy NB. Gets executed
followed by creation of an instance that is returned.
o=. conew 'customer' NB. Gets executed
So, end of the call, c is a 'customer' object.
From this point on, I want to add attributes dyamically to the class and the
instance.
c add ('name' ; 'MyName') NB. Format <Name,Value> pair
Internally the add verb does the following:
a) injects name as an attribute in the class 'customer'
b) instantiate that value in the instance 'c' that I have.
NB. Set the name as an attribute of the class (how?)
name_c =: 'MyName' NB. Gets executed
I am getting a good lot stuck on getting the strings out in the right format
:(!
Further, I am unsure on how to execute the blocks created. (I have read it
somewhere....just that I am grappling with the concept and the
implementation simultaneously and so thought I would ask the forum members
for a fast response)
Since J has all these possibilities, I wonder if someone has tread this path
before. In that case, can I get some reference code? Thanks.
Regards,
Yuva
On 12/19/06, Miller, Raul D <[EMAIL PROTECTED]> wrote:
Yuvaraj Athur Raghuvir wrote:
> 1) Can I add an attribute or a method to a class elsewhere?
Yes. For example attr_class1_=: 'whatever'
> 2) Is J strongly typed? Or can the client invoke a method on an
> instance as long as the method exists on the instance and uses no
> other information?
Er... http://en.wikipedia.org/wiki/Strong_typing
J is not statically typed. For example attr_class1_=: 3.1415 is always
syntactically valid.
J is type safe. For example 1 + 'whatever' will produce a domain error.
J allows type conversion where this does not conflict with type
safety. For example,
1 + 3.1415 is legal.
J does allow access to the raw bytes underlying data, more or less, in the
sense
that there are functions which produces those raw bytes.
J's type system is fairly regular with only a specified set of built-in
types. This set
is rich (can represent most anything representable by a computer), but not
extensible.
[Note that you can create arbitrary classes and arbitrary instances of
classes, but
those are not distinct types in the sense I'm using here.]
J allows the class of an object to be changed at run-time (though you have
to have
a deep understanding of J to pull this off, and I've not seen it used).
J programs are determnistic unless they depend on non-deterministic i/o.
But, yes: all you need to invoke a method are an object reference which
has
that method. (Or a class reference, for static methods.) Of course, if
the
argument you supply is within the domain of that method you'll probably
be getting a run-time error.
> Some implementation snippets would help where the answer is a "yes".
If the above examples are inadequate, feel free to ask more questions.
Note also that the concept underlying J's implementation of classes and
objects is called "locales" (which is distinct from, though vaguely
analogous
to "locals"). This might help you if you are searching jsoftware.com for
documentation. The reference for the raw primitives is at
http://jsoftware.com/help/dictionary/dx018.htm
But if you download J a better place to start would be the locale and OO
programming labs. (And, those will be easier to understand if you
understand the basics of J's syntax and data types, and J's concepts
of "rank".)
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm