Examples of nontrivial use of fexpr

I am looking for (real world) the use of fexprs where they are used as opposed to what can be done with lazy pricing.

Most of the examples that I could find use fexprs only to perform a conditional evaluation, for example, to short circuit "and" operative (Evaluate the first argument if false, do not evaluate the second and directly return false).

I am looking for β€œuseful” applications, that is, where using fexpr leads to the fact that the code is β€œbetter” (cleaner) than what could be done without fexprs.

+6
source share
2 answers

There are two main reasons why you would like to use fexprs.

The first is that they allow you to evaluate arguments an arbitrary number of times. This allows you to implement operators that lazily evaluate their arguments, as you suggested. Constructs constructed in this way can also evaluate their arguments more than once. This allows you to implement loops through fexprs!

Another case for conversion. Code conversion is basically a way of writing a compiler on top of an existing Lisp. Although it uses macros rather than fexprs, cl-who is a great example of what kind of conversions can be done.

+2
source

Fexpr is somewhat orthogonal to a lazy / impatient assessment.

The usual approach to functions is to evaluate the arguments of a function and then call the result. Lazy eval still behaves like this, it just delays the evaluation until the parameter is used.

The usual macro approach is to pass unvalued arguments to a template that evaluates everything that is not quoted. The resulting AST fragment is introduced into the call area, where it is usually evaluated again. This works the same with lazy eval.

Fexpr's historically insane approach is to pass unvalued arguments to a function that does what they like. The result is entered directly into the call site and is usually not evaluated automatically.

fexpr is pretty close to arbitrary conversion. That way you can implement macros and lambda with them. You can also implement any hybrid of your desired / lazy grade you want. Similarly, you can implement fexpr, the default lazy eval and explicit calls to eval () in different places to force impatient behavior.

I do not think that I would characterize fexpr as a simple solution for implementing lazy eval, although in treatment it is worse than illness.

+1
source

Source: https://habr.com/ru/post/985544/


All Articles