I like the =.. and =:: proposals, (though perhaps as adverbs... see below) 

I've done some work on defaults, and though I had not considered nesting, I 
believe its not essential.  What is essential is replacing nulls (i.0), and the 
flexibility to have defaults not just for trailing arguments.  With that said, 
your proposal doesn't affect my solution which is: 


linearize =: , $~ 1 -.~ $dflt =: ((#@] linearize@{. [) [`]@.(0 = #@>@[)"0 0 
])&boxopen

dflt is a verb, that should have the default arguments on the left (but doesn't 
currently)

dflt&(5 ; 6) 3;4 
┌─┬─┐ 
│3│4│ 
└─┴─┘ 
dflt&(5 ; 6) 3 7 
┌───┬─┐ 
│3 7│6│ 
└───┴─┘ 
dflt&(5 ; 6) a: 
┌─┬─┐ 
│5│6│ 
└─┴─┘ 

dflt&(5 ; 6)  i.0 
┌─┬─┐ 
│5│6│ 
└─┴─┘
dflt&(5 )  7;8 NB. controversial for single (unboxed) defaults probably should 
keep any non null or a: arg unchanged in full.  
┌─┐ 
│7│ 
└─┘
dflt&(5 ) '';7 NB. controversial 
┌─┐ 
│5│ 
└─┘ 



dflt&(5 ) 7 NB. controversial boxing.  single unboxed default should not box 
arg.  single boxed default should box arg.
┌─┐ 
│7│ 
└─┘

dflt&(5 ; 6) '';4 
┌─┬─┐ 
│5│4│ 
└─┴─┘


NB. set defaults as a function of all arguments
(] dflt (1&{:: * 2&{::) ; (0&{:: * 2&{::) ; 1&{:: * 0&{::) 4;'';5 
┌─┬──┬─┐ 
│4│20│5│ 
└─┴──┴─┘ 

NB. semi graceful error
(] dflt (1&{:: * 2&{::) ; (0&{:: * 2&{::) ; 1&{:: * 0&{::) '';'';5 
┌┬┬─┐ 
│││5│ 
└┴┴─┘ 


NB. handles nesting

((5 ; 6) ; 7) dflt~ each ('';2);'' 
┌─────┬───┐ 
│┌─┬─┐│┌─┐│ 
││5│2│││7││ 
│└─┴─┘│└─┘│ 
└─────┴───┘ 



I also have a version for gerunds, that has syntax sugar for passing it a non 
gerund (useful for default argument to adverb which can take just a single arg 
or gerund or multi args)


isgerund =: 0:`(0 -.@e. 3 : ('y (5!:0)';'1')"0)@.(0 < L.) :: 0:
isNoun =: (0 = 4!:0 ::0:)@:<
isgerundA  =: 1 : ' if. isNoun ''u'' do. isgerund m else. 0 end.'

eval  =: 1 : 'if. 2 ~: 3!:0 m do. m else. a: 1 :  m end.'
ismodstring  =: 1 : 'if. 0 = 4!:0 <''u'' do. try. q =.  m eval catch. 0 return. 
end. 1 2 e.~ 4!:0 <''q''else. 0 end. '
ncS =: 3 : 'z=.y 1 :y label_. 4!:0 <''z'' ' ::(_2:)
lrA =: 1 : '5!:5 < ''u'''

ncA =: 1 : 'if. 3 ~: 4!:0 < ''u'' do. if. m ismodstring do. m ; ncS m else. 0 
;~ ''('', m lrA ,'')'' end. else. 3;~ ''('', u lrA ,'')'' end.'
toG =: 1 : ' if. 1 2 e.~ 1 {:: u ncA do. a =. (m) eval else. a=.u end. 5!:1 < 
''a'''
ar =: 1 : '5!:1 <''u'''


dfltG =: 1 : 'u  1 :''2 : ''''if. -. u  isgerundA do. m =. u toG end. linearize 
n [^:((a: ar) -: ])"0 (#n) {.!.(a: ar) m'''' u'''


a: (+:`''  dfltG) 5!:0 
+:

 a: ar`*: (+:`-:  dfltG) 
┌──┬──┐ 
│+:│*:│ 
└──┴──┘ 


a: (+:`-:  dfltG) 
┌──┬──┐ 
│+:│-:│ 
└──┴──┘
*: (+:`-:  dfltG) 
┌──┬──┐ 
│*:│-:│ 
└──┴──┘

as to =.. and =:: adverb proposals,

x (noun =::) y would assign default values in noun for null elements of y.

  (verb =::) 'y' would be equivalent to (y) =: verb y 


x (verb =::) 'y' would be equivalent to (y) =: x verb y NB. + =::  like += in C 
and other languages.

 (noun ar`verb =::) 'y' would be equivalent to (y) =:  verb y (with default 
value of noun if unassigned or null)
x (v0`v1 =::) 'y' would be equivalent to (y) =:  x v1 y (with x v0 null (i.0) 
as default value if y is unassigned or null)

 (a: =::) would behave as Jose wants it: x =: y (as a normal verb.)

________________________________
From: Jose Mario Quintana <[email protected]>
To: Programming forum <[email protected]> 
Sent: Tuesday, July 4, 2017 9:01 AM
Subject: Re: [Jprogramming] Request for comments: multiple assignment



0.  Will  `  be still supported (maybe I missed in the BNF description)?

1. Copula is not a word (noun, verb, adverb or conjunction) it is, I think,
a punctuation mark which makes it very inconvenient sometimes (for example,
it cannot be processed by `:6) .  However, the multiple assignment form can
be defined as a verb and it becomes, in my opinion, very useful.  This is
done in Jx via the verbs  =..  and  =::  ; you might consider to add these
extensions to the official interpreter.



On Tue, Jul 4, 2017 at 1:40 AM, HenryRich <[email protected]> wrote:

> Here is a feature that I have wanted for a long time:
>
> http://code.jsoftware.com/wiki/System/Interpreter/Requests#
> Expanded_Multiple_Assignment
>
> It attempts to solve the problem of moving verb arguments into
> variable-names.  Allows defaults and multilevel arguments.  I will
> implement this within a month or so, so get your comments in ASAP.
>
> Henry Rich
>
> ---
> This email has been checked for viruses by AVG.
> http://www.avg.com
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to