A J approach where, v is a monadic resource acquisition function (file open, acquire lock) with a defined inverse whose result we normally don't care about (want the result of u). v inv should raise an error instead of return an error code. there are 2 options for y argument to v inv :
v inv v y (independent of [x] u v y) NB. open file :. close file as example or v inv [x] u v y NB. read file :. write file where u changes file contents. write file as inverse to read file is dyadic (legal inverse), and so function is incorrect for purposess of read write duality, but such monadic :. dyadic inverse functionality is easy to write. An interesting concept about duality, rather than the "inversality" term that duals in J as used for is: :. (dual definition) is an alternative to gerunds where a modifier can access (any defined) the dual as a 2nd parameter included in u or v, where inverses reflect the core J library, but with user verbs, or some of these locks, acquire/release is close to invesality, there's no conceptual limit on defining a duality related to modifer purpose. u for initial simplicity is dyadic e is error + cleanup (v inv) function that will pickup error in either u or (v inv): (13!:12 (13!:8) 13!:11 [ v inv@]) but where e can be invoked on error of v u or v inv. e =: ( :: (13!:12@[(13!:8)13!:11 )) up1=: 2 : ' ( v inv(@])e ] u ( :: ( (13!:12@[ (13!:8) 13!:11)@''''@(v inv@])) )) v e ' and then for u ambivalence uped =: (@]) up1 ]: : up1 to show the 3 possible error "positions" and no error behaviour 2 +up1(-&> ::] :.((-@<)@(1!:2&2))) 3 _3 |domain error | 2 +up1(-&> ::] :.((-@<)@(1!:2&2)))3 Error in v inv (-@< after display) display shows that v was executed: _3 2 +up1(- :. (1!:2&2) ) '3' |rank error | 2 +up1(- :.(1!:2&2))'3' Error in v (-) bug somewhere (perhaps even my code) that makes this a rank error instead of domain error. No display shows v inv did not execute. 2 +up1(< :. (1!:2&2) ) 3 ┌─┐ │3│ └─┘ ||domain error | 2 +up1(< :.(1!:2&2))3 Error in u. v inv (display) still executes when u causes error. 2 +up1(- :. (1!:2&2) ) 3 _3 _1 No error. v inv executes return value is x u v y (_1) +:uped(- :.(1!:2&2))3 _3 _6 On Sunday, May 1, 2022, 07:52:05 a.m. EDT, Hauke Rehr <hauke.r...@uni-jena.de> wrote: which seems to have been done before or came up independently in D, you have slightly more fine-grained options <open file> scope(exit){<close file>} <actual use of file starts here> <generate opening xml tag> scope(success){<generate closing xml tag>} scope(failure){<some cleanup>} <contents inside that tag are generated here> a spontaneous reaction: In J, I’d like to use generators like fileworker =. workfile thatone 'exitstatus result' =. verb_using_file&.fileworker arg_of_verb or memlocker =. lockmem mutex 'exitstatus result' =. atomic_verb&.memlocker arg_of_verb [do we even need exitstatus?] one could even make them generate adverbs but using &. makes the intent clear so I’d prefer not adding too much syntactic sugar – but as always, there are different tastes and digestive systems (called minds) … so the argument should be passed and the cleanup assigned as the obverse, potentially supplementing the result with an exit status value/error code would that interfere with your ideas? Am 01.05.22 um 07:54 schrieb Elijah Stone: > an idea worth stealing -- ---------------------- mail written using NEO neo-layout.org ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm