The spoiler to the challenge below ( http://www.jsoftware.com/pipermail/programming/2007-December/009267.html ) follows after several blank lines.
The challenge is to give a counterexample to the following J myth. 2. Difficult: Only “caps make it possible to define a wider range of functions as unbroken trains […] Thus, h=: >. % [: <. + * - 2.5 h 4 _0.4 ” Hint: one can cheat by searching the Forum. Bonus puzzle: Find a cap replacement verb for the following utilization, “since the domain of the cap is empty, it can be used (with :) to define a function whose monadic or dyadic case invokes an error.” The best description I have seen of what [: does in the context of trains is 大平 徹 (O^DAIRA, To^ru K.)’s alternative given in http://www.jsoftware.com/pipermail/general/2002-September/008617.html . It clearly shows [:’s split nature: a dummy verb with an implicit side effect as an adverb. A slight variation follows. h=: >. % [: <. + * - 2.5 h 4 _0.4 h NB. It is an unbroken train >. % [: <. + * - +--+-+---------------+ |>.|%|+--+--+-------+| | | ||[:|<.|+-+-+-+|| | | || | ||+|*|-||| | | || | |+-+-+-+|| | | |+--+--+-------+| +--+-+---------------+ >. % ([: <. (+ * -)) CA=. [ NB. Verb P=. @:] NB. Adverb h=. >. % CA <.P + * - 2.5 h 4 _0.4 h NB. It is also an unbroken train >. % CA <.@:] + * - +--+-+----------------------+ |>.|%|+--+---------+-------+| | | ||CA|+--+--+-+|+-+-+-+|| | | || ||<.|@:|]|||+|*|-||| | | || |+--+--+-+|+-+-+-+|| | | |+--+---------+-------+| +--+-+----------------------+ >. % (CA (<.@:]) (+ * -)) Boss’ recent comb3 jem is a more interesting case, comb3=. [:; [:(,.&.><@;\.)/ >:@[EMAIL PROTECTED] c3=. [;P [(,.&.><@;\.)/P >:@[EMAIL PROTECTED] comb3 NB. It is an unbroken train. [: ; [: (,.&.> <@;\.)/ >:@-~ [\ [EMAIL PROTECTED] +--+-+---------------------------------------------------------------+ |[:|;|+--+----------------------------+-----------------------------+| | | ||[:|+------------------------+-+|+------------+-----+--------+|| | | || ||+---------+------------+|/|||+--------+-+|+-+-+|+--+-+-+||| | | || |||+--+--+-+|+-------+--+|| ||||+--+-+-+|~|||[|\|||i.|@|]|||| | | || ||||,.|&.|>|||+-+-+-+|\.||| |||||>:|@|-|| ||+-+-+|+--+-+-+||| | | || |||+--+--+-+|||<|@|;|| ||| ||||+--+-+-+| || | ||| | | || ||| ||+-+-+-+| ||| |||+--------+-+| | ||| | | || ||| |+-------+--+|| ||+------------+-----+--------+|| | | || ||+---------+------------+| || || | | || |+------------------------+-+| || | | |+--+----------------------------+-----------------------------+| +--+-+---------------------------------------------------------------+ [: ; ([: (((,.&.>) ((<@;)\.))/) (((>:@-)~) ([\) ([EMAIL PROTECTED]))) c3 NB. It is an unbroken train as well [ ;@:] [ (,.&.> <@;\.)/@:] >:@-~ [\ [EMAIL PROTECTED] +-+--------+---------------------------------------------------------------------+ |[|+-+--+-+|+-+-----------------------------------+-----------------------------+| | ||;|@:|]|||[|+----------------------------+--+-+|+------------+-----+--------+|| | |+-+--+-+|| ||+------------------------+-+|@:|]|||+--------+-+|+-+-+|+--+-+-+||| | | || |||+---------+------------+|/|| | ||||+--+-+-+|~|||[|\|||i.|@|]|||| | | || ||||+--+--+-+|+-------+--+|| || | |||||>:|@|-|| ||+-+-+|+--+-+-+||| | | || |||||,.|&.|>|||+-+-+-+|\.||| || | ||||+--+-+-+| || | ||| | | || ||||+--+--+-+|||<|@|;|| ||| || | |||+--------+-+| | ||| | | || |||| ||+-+-+-+| ||| || | ||+------------+-----+--------+|| | | || |||| |+-------+--+|| || | || || | | || |||+---------+------------+| || | || || | | || ||+------------------------+-+| | || || | | || |+----------------------------+--+-+| || | | |+-+-----------------------------------+-----------------------------+| +-+--------+---------------------------------------------------------------------+ [ (;@:]) ([ ((((,.&.>) ((<@;)\.))/)@:]) (((>:@-)~) ([\) ([EMAIL PROTECTED]))) 10 (c3 -: comb3) 20 1 Both seem to have similar performance. 6!:2 '5 comb3 52' 0.435806 6!:2 '5 c3 52' 0.439758 7!:2 '5 comb3 52' 144368768 7!:2 '5 c3 52' 144368704 The other suggested use of [: is emulated, for example, as follows, abs=: | : [: res=: [: : | res _4 0 5 |domain error: res | res _4 0 5 |[-3] abs _4 0 5 4 0 5 3 res _4 0 5 2 0 2 3 abs _4 0 5 |domain error: abs | 3 abs _4 0 5 |[-2] cap=. + a:"_ abs=: | : cap res=: cap : | res _4 0 5 |domain error: cap | res _4 0 5 |[-5] 3 res _4 0 5 2 0 2 3 abs _4 0 5 |domain error: cap | 3 abs _4 0 5 |[-1] (The [:’s redundancy is not a sufficient reason for removing it from the language since many other primitives are also redundant but I am still wondering why a superfluous anomaly had to be introduced.) ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
