gosukiwi / Blueberry

A beautiful programming language with clean syntax which compiles to PHP
MIT License
63 stars 10 forks source link

List comprehension #32

Closed gosukiwi closed 9 years ago

gosukiwi commented 9 years ago

Ideally I'd love to implement Ruby blocks, but PHP api itself isn't very keen on passing closures around. So I guess list comprehension is good enough.

Somewhat like CoffeeScript and Python do.

2 * i for i in [1..10] where i % 2 == 0

hikari-no-yume commented 9 years ago

I don't see why you couldn't do blocks.

For list comprehensions, would we also have generator comprehensions for PHP 5.5+?

gosukiwi commented 9 years ago

Blocks would be awesome, I just think it might be harder to do, and not gain much benefit as existing PHP libraries don't really embrace closures.

Uhm, for now I think I'd rather make it compatible with PHP 5.3+ mainly because a bunch of people are running those versions.

According to WP Stats 32.9% of all WP installations use PHP 5.2. I'd really like to support 5.3+

It's always possible to make a compiler switch of course. But I don't really want to add more complexity. Just keep things simple.

hikari-no-yume commented 9 years ago

Well, they don't have to use generator comprehensions if they don't want to, list comprehensions would also be an option.

gosukiwi commented 9 years ago

I took the shot and implemented it in 57c009d1704f89d93ec0fa7a73ddb0af9c61c4c6. The codegen might need some work but this way is quite flexible.

Closing it for now.

hikari-no-yume commented 9 years ago

No generator comprehensions? Aww.