Pete Dietl (22 May 2020 09:18) > As for a name for $(cond), we could call it > $(alu ...) > And put arithmetic and logical operations in it :)
Amusing as this is, I don't think it's a good name ! > I don’t like using $(cond) > Because because I sort of want to option to implement cond like in Scheme. There are already $(if, test, yes, no) evaluating to yes if test is a non-empty string, no if it is empty; $(or conds,...) evaluating to the first non-empty condition, empty if all are empty; and $(and conds...) evaluating to the first empty condition, else the last parameter. So no need for cond. I would tend towards defining a $(compare before, after, rise, same, fall) which evaluates to rise if before < after, same if before == after and fall if before > after. That packs all of the <, <=, >, >=, == and != tests into one; when you want the cases where two come out the same, $(if $(compare $(a), $(b),,y,y),ge,lt) will evaluate to ge if $(a) >= $(b), else to lt, so that repeating y saves repeating a potentially long ge text. Obvious similar usage can handle the other "use same value in two cases" options. On the need for a named function: note that $*, $(*), $(*D), $(*F) and likewise for $+ all have meanings already, so overloading them to also be the multiplication and addition operators sounds imprudent, even if it is possible. I think $(math op, args) makes sense, so as to have only one entry-point in both code and documentation. I think each operator should initialize a result to its first argument then use the operator to combine the current result with each successive argument; so $(math *, 7) evaluates to 7, $(math /, $(size) 1024 1024) turns a size in bytes into a size in MiB and $(math -, $(total) $(subs)) gives the residue when each sub has been subtracted from a total. But then I've been influenced by Lisp, so I would think that. I'm sure there's a quote somewhere about every language eventually growing an implementation of Lisp. Perhaps it's best to stop short of actually dong that fully, though ... Eddy.