NB. File definitions for'J For C Programmers' NB. Copyright (c) 2002 Henry H. Rich cocurrent 'z' NB.*ReadFile v-- Monad. y. is boxed filename, result is character-list contents ReadFile =: 1!:1 NB.*WriteFile v-- Dyad. y. is boxed filename, x. is character-list contents WriteFile =: 1!:2 NB.*AppendFile v-- Dyad. y. is boxed filename, x. is character-list contents AppendFile =: 1!:3 NB.*EraseFile v-- Monad. y. is boxed filename, which is erased EraseFile =: 1!:55 NB.*PublishEntryPoints v-- Dual. y. is string of entry-point names, separated by spaces NB. x. is the level number at which we should publish the entry points (default _1, 'z') NB. we publish these names in the locale at position x. in the path PublishEntryPoints =: 3 : 0 _1 PublishEntryPoints y. : NB. The rhs of the assigment below interprets the names as gerunds path =. '_' (,,[) x. {:: (<,'z') ,~^:(-.@*@#@]) 18!:2 current =. 18!:5 '' l =. ,&path^:('_'&~:@{:)&.> ;: y. r =. ,&('_' (,,[) > current)@(({.~ i:&'_')@}:^:('_'&=@{:))&.> ;: y. NB. The gerund assignment requires more than one name, so duplicate the last: ('`' , ;:^:_1 (, {:) l) =: (, {:) r ) NB.*Display v-- Monad. Type y. on the terminal Display =: (i.0 0)"_ ((1!:2) 2:) NB.*BoolToNdx v-- Monad. y. is a Boolean list; result is indexes of 1s BoolToNdx =: (# i.@:#)"1 NB.*Endtoend a-- Dual. Apply [x] u. on y.; run results together Endtoend =: ;@:(<@]:) NB.*Butifnull c-- Dual. Conjunction: u. unless y. has no items; then v. Butifnull =: ((]."_)`[.) @. (*@#@]) NB.*Butifxnull c-- Dual. Conjunction: u. unless x. has no items; then v. Butifxnull =: ((]."_)`[.) @. (*@#@]) NB.*Ifany a-- Dual. Execute u., but skip it if y. has no items Ifany =: ^: (*@#@]) NB.*Ifany a-- Dual. Execute u., but skip it if x. has no items Ifanyx =: ^: (*@#@[) NB.*Bivalent c-- Dual. u. v. y. if monad, x. u. (v. y.) if dyad Bivalent =: [. ^: (1:`((]`].)`:6)) NB.*Xuvy c-- Dual. [x.] (u. v.) y. Xuvy =: 12 : 'x. y.' NB.*Yuvx c-- Dual. [y.] (u. v.) x. Yuvx =: 12 : '(x. y.)~' NB.*Ux_Vy c-- Dual. (u. x.) v. y. Ux_Vy =: 12 : '(y.~ x.)~' NB.*Uy_Vx c-- Dual. (u. y.) v. x. Uy_Vx =: 12 : '(y.~ x.)' NB.*Vx_Uy c-- Dual. (v. x.) u. y. Vx_Uy =: 12 : '(x.~ y.)~' NB.*Vy_Ux c-- Dual. (v. y.) u. x. Vy_Ux =: 12 : '(x.~ y.)' NB.*UsedToSelect a-- keep items of y. for which u. y. is 1 UsedToSelect =: 11 : 'x. # ]' NB.*LoopWithInitial c-- Monad. u. is verb, n. is initial value NB. u. is applied to the items sequentially. At each application NB. of u., x. is the next item of the initial y. and y. is NB. the result of the previous execution of u. (initial y. is n.) LoopWithInitial =: [.&.>/\. &.(,&(]. (] <) ].))&.|.&.(<"_1)