Created
June 14, 2014 17:43
-
-
Save snipsnipsnip/6f00cab377bb74b6b6cd to your computer and use it in GitHub Desktop.
attr_reader, attr_writer and attr_accessor in J
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coclass 'attr' | |
attr_reader =: monad define | |
loc =. > coname '' | |
names =. ;: y | |
dup =. ((# names) & $) & < | |
fullnames =. names ,. dup ('_' , loc , '_') | |
". joinstring"1 (dup 'get_') ,. fullnames ,. (dup '=: 3 : ''') ,. names ,. (dup '''') | |
) | |
attr_writer =: monad define | |
loc =. > coname '' | |
names =. ;: y | |
dup =. ((# names) & $) & < | |
fullnames =. names ,. dup ('_' , loc , '_') | |
". joinstring"1 (dup 'set_') ,. fullnames ,. (dup '=: 3 : ''') ,. names ,. (dup '=: y''') | |
) | |
attr_accessor =: monad define | |
attr_reader y | |
attr_writer y | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment