Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Function arguments with default values (https://forums.graalonline.com/forums/showthread.php?t=134264706)

xXziroXx 10-04-2011 08:23 AM

Function arguments with default values
 
You know what would be *really* awesome? If you could define a default value to function arguments, Python style.

PHP Code:

function argumentTest(temp.foobartemp.barfoo=true

In the above example, temp.barfoo would be set to true if a value isn't defined in the function caller.

Can haz plz? :cry:

salesman 10-04-2011 04:36 PM

Graal just treats undefined variables as null, so why not just do something like this?
PHP Code:

function argumentTest(temp.foobartemp.barfoo) {
  
temp.barfoo temp.barfoo == null true temp.barfoo;
  
// ...



xXziroXx 10-04-2011 05:18 PM

Quote:

Originally Posted by salesman (Post 1669975)
Graal just treats undefined variables as null, so why not just do something like this?
PHP Code:

function argumentTest(temp.foobartemp.barfoo) {
  
temp.barfoo temp.barfoo == null true temp.barfoo;
  
// ...



Because of convenience mainly, just like most of the other suggestions posted here.

Tolnaftate2004 10-04-2011 05:37 PM

Better yet, || and && shouldn't return boolean, but rather the last-evaluated operand:

PHP Code:

function foo(bar,baz) {
  
bar bar || true;
  
baz baz || "Hey, how're you doin'? ;)";


e: You saw nothing.
e2: Actually, if || and && are using the same optimization as here, that would have to change for this to make any sense.

But perhaps we could just have ||= and &&=

PHP Code:

function foo(bar,baz) {
  
bar ||= true;
  
baz ||= "Hey, how're you doin'? ;)";




All times are GMT +2. The time now is 06:16 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.