These 2 lines need to be defined in a module.  Wont
work at top level.
a1=: 6
temp61=:  >:@(a1&*)@([&a1=. 12)

   temp61 5
61
   a1
6

What temp61 does is temporarily set the a1 global
variable to 12, and uses that for the rest of the
line.  That is very cool because you can have default
functionality, and over-ride it.
(Incidentally, it doesn't work at top level because
a1=. newval at top level changes the global value. 
Perhaps making =. at top level not create a permanent
variable (exists after sentence or function has
finished) would be better.)

Similarly with a verb,
v1=:+
temp62=: (2&v1)@([&v1=. -)

   temp62 3
_1
   v1
┌─┐
│+│
└─┘

  This lets you override a verb.  Some applications
could be to affect deeply nested functions, optionally
providing customized behaviour to default
functionality.  Dataset joining/Relation mapping is
the domain I'm attempting to apply it to atm.

Unfortunately, there may be a bug, or it just doesn't
work with deeper nested function chains.  I will just
show the code I'm working with and appologize if it is
needlessly complicated. (should place in a module to
be sure to reproduce)
hept=:%&2@(* (-&3@(5&*)))
oct=:(* (-&2@(3&*)))
p7=:hept (21+i.43)
p8=:oct (19+i.40)
INTJOINER =: 'no default value defined yet'
lJoiner=: (([:;+/each@<"1@>@(INTJOINER each)/) # 
(>@([each)/)  )
rJoiner=: (([:;I. each@<"1@>@(INTJOINER each)/){
(>@(]each)/)  )
MultiJoin=: 2&(<@(lJoiner,.rJoiner)"1/\)
c61=: 4 :'(>((100 &|&.>) x)) ="0 1 (>(<.&.>@
((%&100)&.>)) y)'

The above is the necessary definitions to test code
below. INTJOINER is a verb that will select from its
arguments.  For illustratin purposes, it is initially
not set to anything useful.  c61 is a valid option for
INTJOINER.

MultiJoin ([&(INTJOINER=.c61)) p7;p8
|domain error: c61
|       MultiJoin@([&(INTJOINER=.c61))p7;p8

MultiJoin@([&(INTJOINER=.c61)) p7;p8 will produce the
same error.

Another problem though is that the global INTJOINER
has been changed to the local value setting :(
   INTJOINER
&#9484;&#9472;&#9472;&#9472;&#9488;
&#9474;c61&#9474;
&#9492;&#9472;&#9472;&#9472;&#9496;

I can use that to get the answer I'm looking for, but
it should probably be considered a bug that a local
assignment (=.) caused a global change... even if it
was caused by an error in trying to execute a full
sentence.  It defeats the purpose of the technique to
safely over-ride functionality if an uncompleted
sentence changes a global variable that is being
shadowed (probably at great surprise to the user).

> MultiJoin p7;p8 NB. works because INTJOINER was set
globally by error
1071 7105
1177 7701
1918 1825
2059 5985
2512 1281
3010 1045
3186 8640
3744 4485
3940 4033
4347 4720
4774 7400
5221 2133
5452 5208
6426 2640
7480 8008
8614 1408
8910 1045
9211 1160
9828 2821

It would be very neat if shadowing deeply nested verbs
was supported.  

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to