0

Is it possible to quote result of function call?

For example

(quoteresult (+ 1 1)) => '2

Ford O.
  • 1,394
  • 8
  • 25
  • Althought it is a very basic question, it is very hard to google any learning materials for scheme. – Ford O. Mar 11 '17 at 21:27
  • [Structure and Interpretation of Computer Programs](https://mitpress.mit.edu/sicp/), [How to Design Programs](http://www.htdp.org). – molbdnilo Mar 12 '17 at 08:26

1 Answers1

2

At first blush, your question doesn’t really make any sense. “Quoting” is a thing that can be performed on datums in a piece of source code. “Quoting” a runtime value is at best a no-op and at worst nonsensical.

The example in your question illustrates why it doesn’t make any sense. Your so-called quoteresult form would evaluate (+ 1 1) to produce '2, but '2 evaluates to 2, the same thing (+ 1 1) evaluates to. How would the result of quoteresult ever be different from ordinary evaluation?

If, however, you want to actually produce a quote expression to be handed off to some use of dynamic evaluation (with the usual disclaimer that that is probably a bad idea), then you need only generate a list of two elements: the symbol quote and your function’s result. If that’s the case, you can implement quoteresult quite simply:

(define (quoteresult x)
  (list 'quote x))

This is, however, of limited usefulness for most programs.

For more information on what quoting is and how it works, see What is the difference between quote and list?.

Community
  • 1
  • 1
Alexis King
  • 43,109
  • 15
  • 131
  • 205
  • I need to quote the result because I am building a a quoted representation of scheme program based on input. I will eval it once it is built. Before that happens, I have to quote every list inside to make sure the eval function doesn't try to apply the list head on its tail. – Ford O. Mar 11 '17 at 21:34
  • @FordO. So you are saying you want the result to be the *list* `(quote 2)`? That is, the result of evaluating the expression `(list 'quote 2)`? – Alexis King Mar 11 '17 at 21:36
  • @FordO. Why do you evaluate the forms in the first place? If you nkow what to do `quoteresult` on I guess you could just skip evaluating them in the first place? – Sylwester Mar 12 '17 at 01:10