automatic evaluation for functions of more than one variable

18 views
Skip to first unread message

Ambrose Laing

unread,
Apr 24, 2018, 6:52:17 AM4/24/18
to YASnippet Discussion Group
Hi,

The following snippet allows for the user to input two numbers $4 and $5, and the snippet computes the product $6=$4*$5.  Then after entering a third number $7, the snippet computes a subtraction $8=$6-$7.

${1:$$(format-time-string "%Y/%m/%d")} StockSale --- ${2:<comment>}
       
; Stock Ticker:              ${3:<ticker>}
       
; Price                      ${4:0.00}
       
; Number                     ${5:0}
       
Equity:StockSale            -${6:0.00$(format "%.2f" (* (string-to-number (yas-field-value 4)) (string-to-number (yas-field-value 5))))}
       
Expenses:StockSale:Fee       ${7:0.00}
       
Assets:Bank:Checking:Misc    ${8:0.00$(format "%.2f" (- (string-to-number (yas-field-value 6)) (string-to-number (yas-field-value 7))))}

$0

It works.

However one thing I don't quite like about it is that you need to tab into fields 6 and 8 in order to get them to be computed/updated to reflect the latest values of $4, $5, and $7 (unlike when you have functions of a single variable implemented as mirrors and they are updated automatically).
Is there a way to make sure fields 6 and 8 are updated immediately whenever any of their dependencies (4,5 and 7) are updated, and also to even avoid having to tab into fields 6 and 8 at all?
I think that would be a much better user experience because

a) Since the user is really unable to modify or override the values of fields 6 and 8, there is no good reason (from a UX perspective) why the user should have to tab into those fields.

b) If the updates to fields 6 and 8 are not computed immediately and automatically whenever one of the dependencies (4, 5 and 7) is modified, then what happens is that you can modify one of the dependencies and then exit the snippet, and in that case
the invariants ($6=$4*$5 and $8=$6-$7) are *not* maintained and that is not good in some situations.

So basically I'd like to know how to evaluate $6 and $8 immediately whenever any character is typed into $4, $5 or $7.  Kindly let me know if there is a way to do this already, or whether it is a worthwhile feature request.

Thank you,

Ambrose

Ambrose Laing

unread,
Apr 28, 2018, 8:40:10 PM4/28/18
to YASnippet Discussion Group
Just FYI, this issue was resolved and closed on github.  --- Thank you

Ambrose Laing

unread,
Apr 28, 2018, 8:40:10 PM4/28/18
to YASnippet Discussion Group
I have opened a github issue on this, in case it becomes a feature request.  I'm guessing that it's probably best to discuss it there.


Thank you,

Ambrose

Reply all
Reply to author
Forward
0 new messages