yetibot / yetibot

🤖 Extreme chatops bot for Slack, Discord, Mattermost, IRC 🔧 New contributors welcome 🏗

Home Page:https://yetibot.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sub expressions in xargs are expanded too early

devth opened this issue · comments

In an expression like:

!echo A | echo B `echo C`

The evaluation order is:

  1. echo A
  2. echo C
  3. echo B

echo C needs to be resolved before echo B in order for the parent command to have its final args before evaluating whatever it happens to do (echo just concats but you can imagine a more complex command where some arg is being computed dynamically like gh repos $(list org1 org2 | random).

This is fine and good, but consider a command involving xargs:

!list 1 2 3 | xargs echo `random`

When should random be evaluated? Once per iteration of xargs or just once total? In other words, do you expect to see output like:

40908.934761580305 1
40908.934761580305 2
40908.934761580305 3

Or like:

40908.934761580305 1
190772.4295550155 2
71033.24303309048 3

It becomes more obviously a problem if trying something like:

!karma | xargs echo score of `render {{score}}`

Currently render {{score}} gets expanded early using the full collection of karma data, like:


({:user-id "foo", :score 7}
{:user-id "@yetibot", :score 4}
{:user-id "yetibot", :score 2})

instead of each item in that sequence, resulting in output like:

score of clojure.lang.LazySeq@782c3717 @foo: 7
score of clojure.lang.LazySeq@782c3717
score of clojure.lang.LazySeq@782c3717 <@@yetibot>: 4

In this case we can work around by using render directly:

!karma | xargs render score of {{score}}

But the question remains on how and if sub expressions could be late-evaluated by xargs.