btwael / mammouth

Unfancy PHP
http://mammouth.boutglay.com
MIT License
214 stars 22 forks source link

Anonymous functions? #9

Closed alrik11es closed 10 years ago

alrik11es commented 10 years ago

Is there support for anonymous functions in mammouth?

BTW this looks pretty awesome, if you need some ideas you could take'em from here https://github.com/runekaagaard/snowscript

btwael commented 10 years ago

@alrik11es, tnx for this suggestion, Mammouth support now Anonymous functions

echo(preg_replace_callback('~-([a-z])~', (match)->
    return(strtoupper(match[1]))
, 'hello-world'))

is compiled to:

echo(preg_replace_callback('~-([a-z])~', function($match) { 
    return(strtoupper($match[1]));
}, 'hello-world'));

see this http://mammouth.wamalaka.com/#try:{{%0Aecho%28preg_replace_callback%28%27~-%28[a-z]%29~%27%2C%20%28match%29-%3E%0A%20%20%20%20return%28strtoupper%28match[1]%29%29%0A%2C%20%27hello-world%27%29%29%0A}}

btwael commented 10 years ago

This will be added to npm version v0.2.3 next time.