r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3 Proposals] For discussion of feature proposals

Marco
13-Mar-2011
[990]
Where is the multiplication?
Andreas
13-Mar-2011
[991]
>> foo: func [/bar x] [either bar [x] [99]]
>> apply :foo [(2 < 4) 123]
== 123
>> apply :foo [(5 < 4) 123]
== 99
Marco
13-Mar-2011
[992]
Sorry but you are flying too high for me. I am tring to rewrite my 
sum function using aplly but do not understand how it could be done.
Andreas
13-Mar-2011
[993]
you don't rewrite sum, you rewrite your call of sum
Marco
13-Mar-2011
[994]
The question is to have a simple method of calling whatever function 
which accpets an optional argument without rewriting the code that 
calls it evry time.
Andreas
13-Mar-2011
[995x2]
first, you can already pass none! as value to refinment arguments.
second, instead of your above
summed: either (something) [sum/time 1 2 (something)][sum 1 2]
just use:
t: (something)
summed: apply :sum [1 2 t t]
Marco
13-Mar-2011
[997]
instead of my above
summed: either (something) [sum/time 1 2 (something)][sum 1 2]
I wish I could use
summed: sum/times 1 2 (something) ;also if (something) is none

for every Rebol function and also for my own functions preferably 
without explicitly add none! as a required type.
Andreas
13-Mar-2011
[998]
And how would you pass NONE as a refinement argument value?
GrahamC
14-Mar-2011
[999]
if you have
amount: any [ amount 1 ]
you don't have to have the either
Oldes
14-Mar-2011
[1000x3]
Marco, we use quite often code like:

>> foo: func[/something][
[     either something [ 1 ][ 2 ]
[    ]
>> foo
== 2
>> foo/something
== 1
>>
Also isn't it better to let the authors of the functions decide if 
the functions are able to accept none! or not?
And finally, in your case, why you must use the refinement, when 
you don't use it?

my-sum: func[
	arg1 [integer!]
	arg2 [integer!]
	amount [none! integer!]
][
	arg1 + arg2 * any [amount 1]
]
>> my-sum 1 2 3
== 9
>> my-sum 1 2 none
== 3
Marco
17-Mar-2011
[1003]
in the foo function /something is a refinement and not an _optional_ 
refinement. In your my-sum function amount is not a refinment and 
my-sum 1 2 none == 3 is correct. What I am saying is that the extra 
none! adds polymorphism (but i have not investigated that too much 
so i could be mistaken), so you can write: sum 1 2 or sum 1 2 3 or 
sum 1 2 none without checking for none before calling the function.
Kaj
17-Mar-2011
[1004x2]
Ehm, the nature of refinements is that they're optional
And you can't write SUM 1 2 without a refinement if you have an extra 
AMOUNT parameter. The number of parameters is fixed in REBOL. The 
way to have optional parameters is to use refinements (or a BLOCK! 
argument)
Gregg
17-Mar-2011
[1006:last]
I don't see the benefit to the propsal at this point.