con2 / emrichen

A Template engine for YAML & JSON
MIT License
107 stars 11 forks source link

Max recursion depth error #66

Closed Sup3rGeo closed 1 year ago

Sup3rGeo commented 1 year ago

Would it be possible to make something like this work without a Max recursion error?

#original.yaml
!Defaults
name: John
---
greeting: !Format "Hi {name}!" 

#composed.yaml
!With
template: !Include original.yaml
vars: 
    name: !Format "{name} and Mark" 

I assume it is because we are referring to name in the definition of name: in composed.yaml, but I would expect that it would use the then already existing John default from original.yaml, resulting in "Hi John and Mark"

japsu commented 1 year ago

No. This is due to the way lazy evaluation works in Emrichen. There is currently no way to redefine a variable in a way that refers to the previous value of the variable.

The only way I could think of would involve some kind of ”eager” (as opposed to lazy) evaluation operator, something like ! in Haskell. I'm struggling to think of a compelling use case for this, though; most of those I can think of can be worked around by using another variable.

Sup3rGeo commented 1 year ago

Thanks for the clarification! Using another variable is indeed the way we have been doing so far, which is not a big deal.