Why does (quote '"foo") go through the Scheme interpreter? It should be syntactically redundant or wrong based on how expressions are constructed in Scheme. quote is used whenever one wants to use a symbol without Scheme thinking it's a variable and strings aren't valid symbols so why is the abbreviation for the quote operator valid when prefixed to strings? Oddly enough (quote '"foo") returns (quote "foo"). Redundancy?
Another strange experiment (symbol? '"foo") is evaluated to #f so that proves that quoted strings still aren't symbols (if the quote works that way in a statement). So, is the ' ignored on strings or does it serve some purpose elsewhere? I am using Chicken Scheme.
Somewhat trivial but kinda mind boggling at the same time.
As stated in the specification:
(quote <datum>) evaluates to the datum value represented by (see section 4.3). This notation is used to include constants.
The above doesn't exclude the quotation of strings, in fact one of the examples in that section is this one:
'"abc" => "abc"
It follows that this is also valid:
''"abc" => ''"abc"
Related
I could redefine quote like this (define quote display), such that '"Hello!" prints Hello. quote is a special form. I would like to know whether or not such a redefinition of a special form is allowed in Scheme. Is it valid to redefine quote?
R7RS-small says that all identifiers must be terminated by a delimiter, but at the same time it defines pretty elaborate rules for what can be in an identifier. So, which one is it?
Is an identifier supposed to start with an initial character and then continue until a delimiter, or does it start with an initial character and continue following the syntax defined in 7.1.1.
Here are a couple of obvious cases. Are these valid identifiers?
a#a
b,b
c'c
d[d]
If they are not supposed to be valid, what is the purpose of saying that an identifier must be terminated by a delimiter?
|..ident..| are delimiters for symbols in R7RS, to allow any character that you cannot insert in an old style symbol (| is the delimiter).
However, in R6RS the "official" grammar was incorrect, as it did not allow to define symbols such that 1+, which led all implementations define their own rules to overcome this illness of the official grammar.
Unless you need to read the source code of a given implementation and see how it defines the symbols, you should not care too much about these rules and use classical symbols.
In the section 7.1.1 you find the backus-naur form that defines the lexical structure of R7RS identifiers but I doubt the implementations follow it.
I quote from here
As with identifiers, different implementations of Scheme use slightly
different rules, but it is always the case that a sequence of
characters that contains no special characters and begins with a
character that cannot begin a number is taken to be a symbol
In other words, an implementation will use a function like read-atom and after that it will classify an atom by backtracking with read-number and if number? fails it will be a symbol.
Consider the following expression in R6RS Scheme:
(syntax ())
When I type this expression into Racket, a (wrapped) syntax object is returned. On the other hand, the same expression yields the (unwrapped) empty list in Chez Scheme.
I am wondering which system is in conformance with the R6RS (or whether both behaviors are allowed by the standard). The relevant paragraph in R6RS is Parsing input and producing output. There, it says:
The output produced by syntax is wrapped or unwrapped according to the following rules
...
the copy of any portion of not containing any pattern variables is a wrapped syntax object.
In (syntax ()) the template does not contain any pattern variables, so it seems that the result should be a wrapped syntax object and that Racket is right.
On the other hand, R. Kent Dybvig, the author of Chez Scheme, is one of the inventors of the syntax-case system so one would expect Chez Scheme to follow the standard closely.
I read some answers here and googled, but had no luck.
I have this:
''a
in scheme (Chez scheme to be exact), and I want to turn it into a string (it's a case in my to-string lambda).
Now, asking if it's a symbol (using the symbol predicate) yields a positive answer, so I know when to operate, but I can't do anything after that since there is no way to get the inner-quote itself.
So basically I can't find a way to turn ''a into "a".
Hopefully this is simple, any help will be appreciated!
This expression:
''a
Is equivalent to this symbol definition (why the double quote, by the way? a single quote suffices):
(quote (quote a))
To turn it into a string, simply do this:
(symbol->string (cadr ''a))
=> "a"
I'm trying to learn scheme by myself. Could anyone tell me why '(quote quote) will output 'quote, and '(quote 'quote) will output ''quote?
Thank you very much!
This expression:
'(quote quote)
... after expanding '<something> to (quote <something>) is equivalent to (quote (quote quote)), notice that the symbol quote is being quoted two times, and this expression is evaluated and printed as ''quote.
On the other hand, this expression:
'(quote 'quote)
... is equivalent to (quote (quote (quote quote))), notice that the symbol quote is being quoted three times, and this expression is evaluated and printed as '''quote.
Take a look at (free, online) How To Design Programs, intermezzo 2. It explains quote in terms of list and cons. If anything in that explanation doesn't make sense, just back up a bit in the textbook.