schemeorder-of-executionr6rs

Forcing left-to-right evaluation order in procedure call


In some cases, it is useful to call a procedure with guaranteed left-to-right evaluation order. For example, when calling a record constructor with data read from a port, order matters. Often the fields are in the same order as in the file, so no reshuffling is required. Therefore, the usual approach of introducing names and ordering via let* is a bit burdensome.

Is there some ready-made syntax in the standard library that provides this functionality? Basically, instead of (f a b c), I expected to write something like (ordered f a b c), which is translated into

(let* ((t0 f)
       (t1 a)
       (t2 b)
       (t3 c))
  (t0 t1 t2 t3))

with new symbols t0 to t3.


Solution

  • Your proposed situation is not nearly common enough to be enshrined as a feature in the standard library, especially given that the workaround with let* is so simple. Additionally, the language empowers you to easily give yourself this feature, with its macro-writing facilities, which means there's even less reason it should be in the standard library. If you find yourself needing to do this a lot, write a macro as part of your library.