yamlscript

Ingy döt Net 2025-02-25T14:56:15.427909Z

I was just huddling with @pez about various things and templating came up, and he showed me Selmer and asked how that might work in YS. A Selmer example:

    {% for item in items %}
  • {{item}}
  • {% endfor %}
A YS program doing template interpolation:
!YS-v0

items =: read('/usr/share/dict/words'):words:shuffle.take(10)

say: |
  
    $(for([item items] "
  • $item
  • " ).join("\n"))
giving:
$ ys template.ys 
  • ply's
  • nontechnical
  • Jinny's
  • evictions
  • lawbreaker
  • masterstrokes
  • Amparo's
  • teed
  • souse's
  • backsliding

😎 1
Ingy döt Net 2025-02-25T16:03:30.291709Z

Or slightly more interesting:

$ cat template2.ys 
!YS-v0

words =: read("/usr/share/dict/words")
  .std/words()
  .filter(/^[a-z]+$/)

defn main(n=10):
  say: |
    
    $((1 .. n).map(li):join:trimr)
defn li(num): |2
  • $num) $(words:rand-nth)
  • $ ys template2.ys 7
    • 1) mother
    • 2) peace
    • 3) roar
    • 4) feta
    • 5) shorts
    • 6) calves
    • 7) retail

    🤘 2