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"
Related
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"
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.
I wrote an alternative fonction to open AutoCAD drawings. However, AutoCAD made it really hard to change how a document is opened when it is ran from Windows Explorer (double click the file with file association). The only method I found is to change a registry key which is "OpenDdeExec". There is a supplied argument (%1) that gives me a unescaped path to the file to open.
I need to ignore the escaping in path or replace the backslashes with double backslashes before it gets parsed as being special characters. In C#, you could do something like string s = #"I\Like random\backslashes"; and backslashes would be taken as the actualy backslashe character. In lisp, the only equivalence I found is quote which has a weird behavior (since it's normal use isn't exactly what I'm trying to acheive).
If I write something like (quote (I\Like random\backslashes)), the outcome will be (I\\Like random\\backslashes) which is ALMOST what I need. However, I have to get rid of the parenthesis. Any idea how I can acheive this?
Note: Doing this (quote I\Like random\backslashes) will break due to the space. It would, however, work on (quote I\Like\backslashes). This would output I\\Like\\backslashes just like I want.
This is the current OpenDdeExec with the described issue:
(OPENFROMSHELL (QUOTE (%1)))
This is unfortunately not possible with AutoCAD's limited LISP.
While writing a function in Racket I accidently put two single quotes in front of a symbol instead of one. i.e. I accidently wrote ''a and discovered some behaviour of nested quotes that seems strange. I'm using DrRacket and tested this with both the Racket lang and the R5RS lang.
(write (pair? (quote (quote a))))
prints: #t .
(write (car (quote (quote a))))
prints: quote
But
(write (quote (quote a)))
and
(write '(quote a)))
Both print: 'a
Can someone tell me why in Scheme (and Racket) the function pair? interprets (quote (quote a))) as a pair of two elements quote and a , but the function write prints out 'a instead of (quote a) .
Putting a quote mark (') around a term and wrapping a quote form around it are identical. That is, they read to the same term.
So all of the following expressions are identical in Scheme:
''a
'(quote a)
(quote 'a)
(quote (quote a))
The quote form means "interpret what comes next as a datum---even if it contains another quote". The sub-term is parenthesized, so it's a list; the inner quote is just a symbol.
In some cases, the printer uses reader-abbreviations like the quote mark (') in its output. I'm a little surprised that you got write to do it, though; for me, it always writes as (quote a).
The square brackets are next to the button 'P' and before 'Enter'. So I want to change them so that I can use them as parentheses instead of square brackets.
It is easier to type that way.
I also found the answer but let the people know in advance.
Preferences -> Editing -> Scheme or Racket -> (check) Automatically adjust opening square brackets.
I don't believe you can configure Dr. Racket to this. Try changing it for your specific operating system.
On the other hand, the Racket reader does not differentiate between square brackets, parentheses, and curly braces. However, it is considered common practice to differentiate them while you're writing code. For instance, the proper way to write a variable assignment is:
(let ([var1 value1]
[var2 value2])
body)
In particular, there are a number of extra Dr. Racket key-bindings which exist to make your life as a programmer easier. Try, for instance hitting Alt+(, really, Meta+(, or the sequence "ESC; (", and you will get a balanced set of parentheses with the cursor placed inside. Same thing goes for brackets and curly braces.
For a list of all such bindings, go to Edit -> Keybindings -> Show Active Keybindings.