Common lisp how to print strings that contain "øæåè" etc - unicode

What format directive shoud use to print the string, e.g "J'T'Emmène Au Vent" without escape characters?
To me it seems that "~a" directive should work, but it does not.
(format t "~a" "J'T'Emmène Au Vent")
prints J'T'Emm\303\250ne Au Vent.
The expected output is J'T'Emmène Au Vent
Note: I use SBCL

Related

Copying a file with robocopy (long name and path, and many spaces) - Missing argument

I tried to copy a file with robocopy, but the PowerShell gives me an error "MissingArgument":
robocopy D:\Enciclopedia` mia\Tutorial` FATTI` DA` ME\Internet\Google\Limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets C:\Users\Raffaele\Desktop Protect,` hide,` and` edit` sheets` -` Computer` (Proteggere,` limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets)` -` Docs` Editors` Help.pdf
File name:
Protect, hide, and edit sheets - Computer (Proteggere, limitare permessi di alcune celle o colonne o righe in Google Sheets) - Docs Editors Help.pdf
File path:
D:\Enciclopedia mia\Tutorial FATTI DA ME\Internet\Google\Limitare permessi di alcune celle o colonne o righe in Google Sheets
I used the same command on a different file, and it works perfectly:
robocopy C:\Users\Raffaele\Desktop\Rapida C:\Users\Raffaele\Desktop\a BULK` MIO.pdf
Could you tell me how can I overcome this problem please?
It's worth heeding Theo's advice: enclosing your file names that contain spaces and other special characters either in single quotes ('...', for verbatim values) or double quotes ("...", if you need string interpolation) is the simplest solution.[1]
While escaping characters individually with `, without enclosing quoting does work, it's visually less obvious and, as in your case, it is easy to miss characters that need escaping:
In PowerShell ,, (, and ) are also metacharacters that require escaping in order to be interpreted verbatim, and you neglected to escape them.
Therefore, escape as follows, using Write-Output as an example command to demonstrate that the names are parsed correctly:
PS> Write-Output D:\Enciclopedia` mia\Tutorial` FATTI` DA` ME\Internet\Google\Limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets C:\Users\Raffaele\Desktop` Protect`,` hide`,` and` edit` sheets` -` Computer` `(Proteggere`,` limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets`)` -` Docs` Editors` Help.pdf
D:\Enciclopedia mia\Tutorial FATTI DA ME\Internet\Google\Limitare permessi di alcune celle o colonne o righe in Google Sheets
C:\Users\Raffaele\Desktop Protect, hide, and edit sheets - Computer (Proteggere, limitare permessi di alcune celle o colonne o righe in Google Sheets) - Docs Editors Help.pdf
List of metacharacters that require individual escaping in unquoted command arguments:
<space> ' " ` , ; ( ) { } | & < > # #
Note:
Of these, < > # # are only special at the start of an argument.
Situationally, . (dot) requires escaping too, namely if the argument can syntactically be interpreted as accessing a variable's property (e.g., Write-Output $env:computername.csv outputs nothing - see this answer).
If you want a $ to be treated verbatim rather than refer to a variable or subexpression, you must escape it too.
For a complete overview of how unquoted command arguments are parsed in PowerShell, see this answer.
[1] See the bottom section of this answer for an overview of PowerShell string literals in general, and this answer for the rules of string interpolation in so-called expandable strings ("..."), specifically.

read-minibuffer function input string with " Punctuation

I write emacs lisp code as follows:
#!/usr/bin/emacs --script
(setq input (read-minibuffer "please input your name:") )
(message "%s" input)
and then I use this code to test standard input:
./test.el
please input your name:hello
hello
this is ok for the first test. But when I put string hello,world to standard input, it occurs error:
please input your name:hello,world
Trailing garbage following expression
And then I put string "hello,world" to standard input, it passed:
please input your name:"hello,world"
hello,world
Then I want to know, how should I do that can get the input string without "
punctuation. I just want to input hello,world, rather then "hello,world".
Thanks
The function read-minibuffer expects the user to input a Lisp object. If you enter hello, it returns a symbol, and if you enter "hello,world", it returns a string.
You probably want the function read-from-minibuffer instead. It returns what the user entered as a string, without trying to interpret it in any way.

LISP: formatting the output of read-line while reading a game board from a file

I am trying to read the board from a text file, but while printing it is also printing the newline and inverted commas as:
(with-open-file (stream "brd1.txt")
(do ((line (read-line stream nil)
(read-line stream nil)))
((null line))
(print line)))
"+ + +^M"
" 3 3 ^M"
"+ + +^M"
" ^M"
"+ + +"
NIL
I am new to LISP. Could somebody help me to format these lines to print the exact board as:
+ + +
3 3
+ + +
+ + +
Input
Apparently you're trying to feed a DOS text file with CRLF-delimited lines to a Lisp implementation that assumes the lines to be LF-delimited in the Unix fashion. Note that read-line strips the newlines, so in our case LF's are stripped, but CR's are treated as ordinary characters and thus remain in the string.
Newlines are platform specific and hence implementation dependent in Lisp. What's more, it seems that neither asdf nor asdf-encodings address this issue. The way I see it you have the following options:
trim the CR's manually e. g. like this:
(string-right-trim '(\#Return) line)
use one of asdf's functions slurp-stream-string and slurp-stream-lines;
use some implementation specific mechanism to specify the encoding;
convert your text file to the Unix format.
Output
As already noted, PRINT is actually a human-readable serialisation. There is a bunch of printing functions on CLHS's page for WRITE and, of course, FORMAT. In order to output a string you can also use WRITE-STRING (without appending a newline) or WRITE-LINE (with a newline).
UPD
Actually UIOP (not ASDF!) exports the utility function UIOP:STRIPLN, which does the following, according to its docstring:
"Strip a string X from any ending CR, LF or CRLF.
Return two values, the stripped string and the ending that was stripped,
or the original value and NIL if no stripping took place.
Since our STRCAT accepts NIL as empty string designator,
the two results passed to STRCAT always reconstitute the original string"
As you can see from the documentation, print "produces output suitable for input to read". Use format instead:
(format t "~a" line)

Idiomatic way to write Clojure code for repeatedly reading lines from the console?

Recently I was writing a little CLI script which needed to repeatedly read dates from the console (the number of dates to read was calculated and could be different each time). Sample Ruby code to give you the idea:
dates = x.times.collect { print "Enter date: "; Date.parse(gets.chomp) }
Just for the heck of it, I wrote the script in Clojure, and wound up using some rather ugly code with swap! and loop...recur. I'm wondering what the cleanest way to achieve the desired effect in Clojure would be. (Clojure does have dotimes, but it doesn't retain the values returned from evaluating the body... as might be expected from a language which emphasizes pure functional programming.)
read-line returns nil when the end of file is reached. On the console that is when you press CTRL-d (CTRL-z on Windows).
You could use this code to take advantage of this:
(doseq [line (repeatedly read-line) :while line]
(do-something-with line))
If you must read a fixed number of lines you can use:
(repeatedly n read-line)
If your goal is to end up with a sequence of exactly x dates entered by user then:
(for [line (repeatedly x read-line)] (DateFormat/parse line))
or using map:
(map DateFormat/parse (repeatedly x read-line))
Beware of lazy sequences in Clojure: user will be asked to enter more dates as they are needed. If your goal is for user to enter all dates at once (say at startup) then use doall:
(map DateFormat/parse (doall (repeatedly x read-line)))
This will read all dates at once, but will parse them lazily still, so date format validation could fail much later in your program. You can move doall one level up to parse promptly as well:
(doall (map DateFormat/parse (repeatedly x read-line)))
And you can use a helper function to read line with prompt:
(defn read-line-with-prompt [prompt]
(print prompt)
(read-line))
Then replace read-line with either:
#(read-line-with-prompt "Enter date: ")
or
(partial read-line-with-prompt "Enter date: ")
You can do something like this:
(defn read-dates [n]
(doall (for [_ (range n)] (java.util.Date/parse (read-line)))))
(def my-dates (read-dates 5)) ;Read 5 dates from console

capturing pva multiline compiler output for emacs compile mode

I wish to compile hSpice pva through emacs.
However, compile-mode does not parse the output properly.
This is the error message the pva compiler generates (the pvaE section):
Parsing include file 'include/constants.vams'
Parsing include file 'include/disciplines.vams'
*pvaE* Syntax error, unsupported syntax or illegal keyword at/before 'vco_cal_dec'
file "/my/path/to/file/veriloga.va", line# 226
(ari_var>=0 ari_var<= 7) : ari_var2=16;
^
This is the compile mode settings that fail to capture the above output:
(defvar verilog-compilation-error-regexp-alist '("^\*pvaE\* .+\n\s+file \"\\(.+\\)\", line# \\([0-9]+\\)" 1 2))
(add-to-list 'compilation-error-regexp-alist verilog-compilation-error-regexp-alist)
Help fixing this regexp will be much appreciated !
The whitespace syntax in your string is wrong. Instead of "\s+" it should be "\\s-+".