In another thread, I was struggling to discuss issues which conflicted
with the topic.

So... I am making a new topic:  Given a nameable entity, in J,
construct a list of characters that can be used in ". to recreate that
nameable entity.   (A nameable entity, in J, is something that can be
enclosed in parenthesis and still be syntactically valid.)

This mechanism is very like the "serialization" that I use in other
languages, so I will call it "serialization".

Serialization is very like J's linear representation, but not quite.
The problem with linear representation, is that it's not always valid
for ".

Here's an example of the reason we cannot use linear representation
(5!:5) for serialization:

  ".'copyoflist=.',5!:5<'list_z_'
|spelling error

Or, more formally:
  ".'copyoflist=.(',(5!:5<'list_z_'),')'
|spelling error

5!:5 does not always generate a character sequence which is valid
between parenthesis, when it is presented with a name which is not a
noun.  Apparently, though, when given a noun, it always serializes the
noun.  [I do not have handy any written guarantees of this, but I also
have not been able to construct any counter examples.)

So, that suggests a serialization mechanism like this:

serializeNamedEntity=: 3 :0
 select. nc <y
   case.0 do. 5!:5 <y
   case.  do. '(',')`:6',~5!:5 <'m' [ m=. 5!:1 <y
 end.
)

And, as a test:

 ".'example1=:',serializeNamedEntity 'serializeNamedEntity'

 'example1' (-:&(5!:1)&<) 'serializeNamedEntity'
1
 ". ']&example3=:',serializeNamedEntity 'example2'[ example2=: a.

 'example3' (-:&(5!:1)&<) 'example2'
1

It's probably also good for adverbs and conjunctions (which is why I
had the entity specified by name, rather than by value).

This depends on undocumented behavior of 5!:5 and of `:6, but it seems
reasonably robust.

It might be worthwhile using 5!:5 directly, and testing its result and
falling back to the longer mechanism only when necessary.

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to