I am considering different ways in which I could modify php to make it more to my liking. My biggest "want" is probably "code blocks"/functions which can be passed to functions which require a body and NOT having them be strings i.e.
xR(1,100)->reduce({$x,$y | $x*$y});
xR(1,100)->reduce([$x,$y | $x*$y]);
funcname($arg1)[$x | echo $x];
Which would be more of a smalltalk/ruby approach. i like the idea of using { } as it is used through out the language to denote blocks. However, I would also like to see a python/javascript notation for arrays/objects/dictionaries i.e.
[1,2,3,4,5,10] is an array and {a:1,b:23} is an associative array/dictionary. The obvious issue is that { } being used for code blocks and dictionaries would be hard to parse. As I am typing aloud I think that perhaps the | in the code block would suffice but what about code blocks with no parameters? One idea which has occured to me would be to use ( ) for code blocks. i.e.
xR(1,100)->reduce(($x, $y | $x*$y));
Another nice thing would be having keyword paramaters but with json that become easy with an object i.e.
functionName({parama:$a,paramb:$b});
but wouldnt:
functionName(parama:$a, paramb:$b);
I guess thats more python esque.
I mean shit while we're at it lets get rid of -> notation and use. instead so now we have and allow an "implicit code block" to be passed in..:
xR(1,100).reduce($x,$y | $x*$y);
Also I would be implementing most of my hash class "natively" so that all arrays become hash objects with all the methods available so stuff like
[1,2,3,4,5].reduce($x,$y | $x*$y); is applicable as is 'this is a string '.trim().replace('a','b').split(' '); etc.
Numbers could be objects too
1.times(2);
No comments:
Post a Comment