read-minibuffer function input string with " Punctuation - emacs

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.

Related

how to remove # character from national data type in cobol

i am facing issue while converting unicode data into national characters.
When i convert the Unicode data into national using national-of function, some junk character like # is appended after the string.
E.g
Ws-unicode pic X(200)
Ws-national pic N(600)
--let the value in Ws-Unicode is これらの変更は. getting from java end.
move function national-of ( Ws-unicode ,1208 ) to Ws-national.
--after converting value is like これらの変更は #.
i do not want the extra # character added after conversion.
please help me to find out the possible solution, i have tried to replace N'#' with space using inspect clause.
it worked well but failed in some specific scenario like if we have # in input from user end. in that case genuine # also converted to space.
Below is a snippet of code I used to convert EBCDIC to UTF. Before I was capturing string lengths, I was also getting # symbols:
STRING
FUNCTION DISPLAY-OF (
FUNCTION NATIONAL-OF (
WS-EBCDIC-STRING(1:WS-XML-EBCDIC-LENGTH)
WS-EBCDIC-CCSID
)
WS-UTF8-CCSID
)
DELIMITED BY SIZE
INTO WS-UTF8-STRING
WITH POINTER WS-XML-UTF8-LENGTH
END-STRING
SUBTRACT 1 FROM WS-XML-UTF8-LENGTH
What this code does is string the UTF8 representation of the EBCIDIC string into another variable. The WITH POINTER clause will capture the new length of the string + 1 (+ 1 because the pointer is positioned to the next position after the string ended).
Using this method, you should be able to know exactly how long second string is and use that string with the exact length.
That should remove the unwanted #s.
EDIT:
One thing I forgot to mention, in my case, the # signs were actually EBCDIC low values when viewing the actual hex on the mainframe
Use inspect with reverse and stop after first occurence of #

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)

specman issue with parsing quotation marks

I am trying to import a string from the unix shell to the program space of specman.
The string i want to import contains quotation marks ("") - for example "hi".
in these cases, the string is not parsed properly . for example
suppose i want to 'echo' some string with quotation marks, i would do the following:
%> echo echo \"\"hi\"\"
will output
""hi""
but if i use the following program, written in e:
<'
extend sys {
run() is also{
print output_from("echo \"\"hi\"\"");
stop_run();
};
};
'>
i get the following output:
output_from("echo \"\"hi\"\"") =
0. "hi"
as you can see - quotation marks are gone. the ones that we see here are coming from the default printing of list values.
I'm not familiar with the output_from action, but I assume it treats the input string as a shell command.
By writing "echo \"\"hi\"\"" what you will essentially get is a string containing echo ""hi"". This is because the \ will be "eaten up" (it's an escape character in e as well). The resulting string is what will be executed, which if you try in the shell will also output the same thing. Try adding an escaped \ as well. I don't have the possibility to start Specman anytime soon so you'll have to try it out.
To test my hypothesis:
// just to see what happens with your original string
var some_string : string = "echo \"\"hi\"\"";
print some_string; // should output echo ""hi""
To try out my solution do something like this:
// might need to fiddle with the escaping here
var some_other_string : string = "echo \\\"\\\"hi\\\"\\\"";
print some_other_string; // should output echo \"\"hi\"\"
You're passing your string through multiple string interpreters. First Specman's, then your shell's string interpreter.
You can debug getting your string through Specman's interpreter first by printing out command you want to pass to the shell first
message(None,"echo [...]")`
Once the printed command looks like it would when you execute it on the shell, then it is ready to be put into output_from command. You can build up the shell command using normal Specman string manipulation functions.

Matlab File I/O concatenation

I have this
fprintf(emailFile, '%s' , fname);
fprintf(emailFile, '%s' , lname);
fprintf(emailFile, '%i' , id);
fprintf(emailFile, '%s\n' , dept);
I need to make it so that the email file shows up fname.lname.id#dept.edu but I don't know what to do for the concatenation.
As Ben Voigt indicated in his comment, your easiest bet to concatenate parts of the email address with the right separator would be to use the fact that fprintf and its cousin sprintf take arguments that control both the formatting and the actual contents of the string.
You can for example create a single string with the complete email address as follows:
completeAddress = sprintf('%s.%s.%i#%s.edu', fname, lname, id, dept);
As you can see, some of the characters control "insert next string argument here", while other characters in the formatting string just get copied to the output string. Note also that if your ID is an integer that could be up to four characters long, and you want to zero-pad for small numbers (0876 instead of 876) you could use e.g. %04i for the formatting.
Writing to an intermediate string (rather than directly to the file) allows you to confirm you have the string you want; you can then write it to the file with a single statement (assuming that emailFile is a valid file ID, of course)
fprintf(emailFile, '%s\n', completeAddress);

arguments of a function in matlab

I am writing a function with two arguments and I want the second argument to be processed as a string. The following code encounters an error
function Derivative = derive ( Matrix9x1 , string Variable )
end
How can I tell it to matlab?
I mean even if the user inputs 1 as the second argument it should be processed as an string
and the user should be able to enter for example omega
The second argument to your function will only be processed 'as a string' if it 'is a string', that is if you enclose it in single quotation marks. If you want to pass a number to a function and turn it into a string for further operations, use the function num2str. If you want to write a function which takes different actions depending on the type of the second argument you're going to have to test that type when the function is called; you might want to look at the functions ischar, isstrprop, isnumeric, and their relations.
Oh, and don't forget that a Matlab 'string' is really an array of characters which are just a convenience 'type' for integers-representing-characters.
Matlab functions are unlike programming language functions. Not that your example in these programming languages will not work either. Passing an integer to a function that expects a string, will give you compilation errors.
The best alternative in Matlab that I can think of will be to check or convert the second input variable inside the function. Maybe this can help you: http://www.mathworks.nl/help/techdoc/ref/typecast.html