Phel v0.41 is out: Fold and Inline phel 🚀 1. Clojure parity fixes </>/<=/>= reject nil instead of coercing 2. Lazy seq alignment map/filter/remove/concat/repeatedly/distinct no longer pre-realize their head. True laziness, Clojure-style. 3. Call-site lowering persistent collection ops, numeric chains, predicates, count/empty?/contains?/deref on tagged values 4. And more stuff -> https://github.com/phel-lang/phel-lang/releases/tag/v0.41.0
__invoke with only this parameter was giving error to me.
That error is intended, not a bug. A struct is already callable as a map (`invoke(mixed $key)` does key lookup), so PHP forces any custom __invoke override to keep a compatible signature: at least one required arg, or variadic. [this] compiles to a zero-arg __invoke() → incompatible → PHP would fatal at class-declaration time, so Phel rejects it at compile with a clear message instead.
Working forms:
(__invoke [this x] ...) ; one arg
(__invoke [this & xs] ...) ; variadic
;; If you want a "call it with no meaningful arg" struct, use a variadic tail and ignore it:
(__invoke [this & _] 42) ; (m) or (m anything) → 42
Just pushed https://github.com/phel-lang/phel-lang/pull/2347 so the error message itself points at the [this & _] trick. 🙏@ahmed1hsn everything what we talked is ready in the latests https://github.com/phel-lang/phel-lang/releases/tag/v0.42.0
@ahmed1hsn this can be helpful -> https://phel-lang.org/blog/php-interop-modern-syntax/
I asked similar question previously, and you provided an implementation using Symfony DBAL. But I'm curious how can we implement src/Entity/Product.php using Phel?
https://symfony.com/doc/current/doctrine.html#creating-an-entity-class
one way I can think of is to make PHP files for Doctrine with PHP Attributes and then consume it from Phel.
@clojurians-slack.htsg how can we use magic methods like __invoke?
@ahmed1hsn Key points:
• Object with __invoke treated as callable. Emitter compiles (d 21) → $d(21), PHP triggers invoke.
• Works in higher-order spots (`map`, filter, apply) too.
• Other magic methods reached via normal interop:
◦ __get / __set → (php/-> obj prop) / (php/oset (php/-> obj prop) val)
◦ __call → (php/-> obj (anyMethod args))
◦ __callStatic → (php/:: Cls (anyMethod args))
◦ __toString → (php/-> obj (__toString)) or (str obj) context
can we define __invoke on defstruct ??
Yes, via inline protocol impl on defstruct.
defstruct emits a real final class extends AbstractPersistentStruct. Inline definterface/`defprotocol` method impls become actual PHP methods on that class. Name one invoke → struct is callable.
(definterface Callable2
(__invoke [this x]))
(defstruct Multiplier [factor]
Callable2
(__invoke [this x] (* x (get this :factor))))
(def m (Multiplier 3))
(php/is_callable m) ; => true
(m 14) ; => 42 ; PHP triggers __invoke
(map m [1 2 3]) ; => @[3 6 9] ; works as fn anywhere@ahmed1hsn however, your idea was pretty good so I will work on it to improve the DX https://github.com/phel-lang/phel-lang/pull/2346
https://github.com/DotFox/edn.c#writer now writes EDN, not just reads it Value-tree writer — serialize to string, buffer, FILE, or a callback. Compact by default, optionally pretty-printed. Ryū-accurate doubles + sortable map/set optional output for stable, round-trip-faithful EDN. Streaming emitter — a YAJL-style push API (edn_emitter_ / edn_emit_) that produces EDN incrementally, no value tree needed. https://github.com/DotFox/edn.c#writer