Program to input string and print it back won't work - printing

I have what I feel should be a very simple bit of code in Common Lisp, all I want it to do is ask for an input from the user, then print it back.
This is my code (The "Before" and "After" printing is from trying to debug, and it showed something odd.
(defun get-input (prompt)
(clear-input)
(write-string prompt)
(finish-output)
(read-line)
)
(let (
(p1 (get-input "Enter: "))
)
(princ "Before")
(princ p1)
(princ "After")
)
When I run this I get the following
This is SBCL 1.2.1, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
WARNING: the Windows port is fragile, particularly for multithreaded
code. Unfortunately, the development team currently lacks the time
and resources this platform demands.
* (load "test.lisp")
Enter: This is my string.
AftereThis is my string.
T
As you can see, my "Before" string isn't even printed, and my "After" string has a strange "e" on the end? And why is it seemingly asking for input when I first run the program?
If anyone could help I would be grateful. Thanks

I believe this is what is happening, in order:
The program evaluates the expression to be bound to p1; this generates your prompt & reads your input
Then it prints "Before"
Then it prints the value of p1, which (I think) has a carriage return at the end, so that the next thing to be printed goes at the start of the line
Then it prints "After", overwriting the first 5 characters of "Before"

Additional Information from sam: SBCL under Windows.
Well, yeah. SBCL's port to Windows is very rough.
See the warning in your output:
WARNING: the Windows port is fragile, particularly for multithreaded
code. Unfortunately, the development team currently lacks the time
and resources this platform demands.
SBCL comes from the Linux/Unix/... world. The port to Windows makes assumptions which are valid for Linux/Unix/... but not for Windows.
One thing is line termination. Windows uses CRLF. Unix uses LF. SBCL under Windows uses LF, IIRC. Probably this can be configured somehow.
If you now use a shell under Windows which expects CRLF conventions and create direct output with SBCL using LF conventions, then you may get strange output...
Thus possible solutions are:
use a Lisp which support Windows conventions. Problem: there are not many. There are really good ones like LispWorks and Allegro CL, but they are relatively expensive. I don't know how Clozure CL does it - it also runs under Windows and is free...
find out how to configure SBCL to use Windows I/O conventions. -> SBCL mailing list
reconfigure your terminal/shell to use Unix LF conventions
I can't reproduce that (CLISP and SBCL in a terminal on the Mac):
CLISP
rjmba:~ joswig$ clisp
i i i i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I 8 8 8 8 8 o 8 8
I \ `+' / I 8 8 8 8 8 8
\ `-+-' / 8 8 8 ooooo 8oooo
`-__|__-' 8 8 8 8 8
| 8 o 8 8 o 8 8
------+------ ooooo 8oooooo ooo8ooo ooooo 8
Welcome to GNU CLISP 2.49 (2010-07-07) <http://clisp.cons.org/>
Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2010
Type :h and hit Enter for context help.
[1]> (load "/tmp/g.lisp")
;; Loading file /tmp/g.lisp ...
Enter: hello
BeforehelloAfter
;; Loaded file /tmp/g.lisp
T
[2]> (quit)
SBCL
rjmba:~ joswig$ sbcl
This is SBCL 1.1.16, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (load "/tmp/g.lisp")
Enter: hello
BeforehelloAfter
T
You might want to tell us your specific implementation and platform combination, plus where Common Lisp does its output...

Related

ed - quoting control characters?

How can I search for control characters in unix ed(1)?
For example
ed somefile.log <<EOF
1,$s/.*\015//
w
q
EOF
doesn't work. Neither does \r. Obviously sed(1), awk(1) and other editors can do this, however ed has the very useful line move (m) command which is all I need within the bash script I am using.
I am able to accomplish what I want within the script by entering the control character directly (escaping it with C-v in vi, C-q in emacs for example), but this means that binary characters must be present in my otherwise printable text script.
ed Transport2SVN-W0177.log <<EOF
g/^M/s/.*^M//p
w
q
EOF
The ^M is actually character 0x0d.
ed doesn't provide any support for converting control characters.
The way you have found of inserting control-characters directly into the script (using Ctrl-V at the keyboard) is portable and it works.
It's possible that particular implementations of ed might support this, but it would not be portable.

How to diagnose errors in LaTeX generated by Doxygen 1.8.x: LT#LL#FM#cr

I've been using Doxygen successfully to generate PDF documentation for a sizable Fortran 90 project since v1.6. After a recent upgrade to Doxygen 1.8, pdflatex is choking with an error I can't understand. From refman.log:
.
.
.
<use classfate__source_a022bf629bdc1d3059ebd5fb86d13b4f4_icgraph.pdf>
Package pdftex.def Info: classfate__source_a022bf629bdc1d3059ebd5fb86d13b4f4_ic
graph.pdf used on input line 607.
(pdftex.def) Requested size: 350.0pt x 65.42921pt.
)
(./classm__aerosol.tex
! Undefined control sequence.
<recently read> \LT#LL#FM#cr
l.25 ...1833ffa6f2fae54ededb}{ia\-\_\-nsize}), \\*
? ?
Type <return> to proceed, S to scroll future error messages,
R to run without stopping, Q to run quietly,
I to insert something, E to edit your file,
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
H for help, X to quit.
Looking at the first 25 lines of classm__aerosol.tex, nothing obviously matches the error message:
\hypertarget{classm__aerosol}{\section{m\-\_\-aerosol Module Reference}
\label{classm__aerosol}\index{m\-\_\-aerosol#{m\-\_\-aerosol}}
}
Contains general aerosol-\/related constants and routines.
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item
subroutine \hyperlink{classm__aerosol_aa06c1f39c6bd34f22be92d21535f0320}{aerdis} (I\-A\-E\-R\-O, M\-A\-E\-R\-O, V\-O\-L, A\-R\-E\-A, M\-U, T\-G\-A\-S, R\-H\-O, A\-G\-A\-M\-M\-A, X\-L\-A\-E\-R, D\-M\-E\-A\-N, N\-A\-E\-R, X\-N\-D\-A\-E\-R, L\-S\-D\-A\-E\-R)
\begin{DoxyCompactList}\small\item\em Return aerosol mass given a volume, based on aerosol size distribution function. \end{DoxyCompactList}\item
real(kind=wp) function \hyperlink{classm__aerosol_a2dff4ff413057e8788fba7270a30c093}{lamsed} (V\-O\-L, H, M\-U\-G, R\-H\-O\-A\-E\-R, A\-G\-A\-M\-M\-A, A\-C\-H\-I, A\-F\-E\-O, K\-O, M\-A\-E\-R, F\-M\-A\-E\-R, F\-A\-E\-R\-S\-S, F\-S\-E\-D\-D\-K)
\begin{DoxyCompactList}\small\item\em Calculate aerosol removal constant and interpolation factor between steady-\/state and decaying aerosol correlations. \end{DoxyCompactList}\item
pure real(kind=wp) function \hyperlink{classm__aerosol_a6d0a04004f49c404c67e0aa69dd39ee1}{fdbend} (V\-E\-L, H\-S\-E\-D, T\-G, R\-H\-O\-G, M\-U\-G, R\-H\-O\-P\-A\-R, C\-A\-E\-R\-O, X\-D\-B\-E\-N\-D, N90\-J)
\begin{DoxyCompactList}\small\item\em Find total impaction efficiency for aerosol deposition considering 90-\/degree bends in a flow path. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Public Attributes}
\begin{DoxyCompactItemize}
\item
integer, parameter \hyperlink{classm__aerosol_a8f604b7ffe3c1833ffa6f2fae54ededb}{ia\-\_\-nsize} = 30
\item
integer, parameter \hyperlink{classm__aerosol_ae71813ecf0c7768af9d6292efb14774f}{ia\-\_\-nmass} = 10
\item
real(kind=wp), dimension(\hyperlink{classm__aerosol_a8f604b7ffe3c1833ffa6f2fae54ededb}{ia\-\_\-nsize}), \\*
Nothing obviously matches the recently read chunk "\LT#LL#FM#cr" and I don't know enough low-level TeX to translate that into something that might actually be in the source text.
Suspecting this might have been fixed in a later version of Doxygen than the one shipping with Linux Mint (v1.8.1.2), I built & installed v1.8.3.1 from source, updated my doxyfile, blew away the old documentation and regenerated it. I get the same baffling error.
There's nothing obvious in refman.log that would indicate missing or broken LaTeX packages and I'm completely at a loss as to what's causing this.
As this still gets a hit on Google when you search:
doxygen missing $ inserted
I would like to add something.
Do not use a PROJECT_NAME containing underscores (_)!
After a brief look into the doxygen's current documentation (I am using 1.8.4) it does not make that explicit.
this will be difficult to solve unless you provide a bit more information - possibly using \errorcontextlines=9999 as suggested in the comments on the question.
as a first short though, the name of the control sequence that can't be found (i.e. \LT#LL#FM#cr) is one defined by the longtable package (documentation, p. 15) - thus adding:
\usepackage{longtable}
to the preamble of the document might help.
If so, according to the doxygen documentation here, adding the following to your configuration file should do the trick:
EXTRA_PACKAGES=longtable

Does Apple AS assembler replace certain NEON instructions with equivalent ones on iOS?

I was trying to use ffmpeg on iOS and was debugging a crash in the optimized arm code. I have discovered that some unsigned (.u16, .u32) instruction have been replaced by signed ones (.i16, .i32). It's easy to see because disassembled instruction on GDB doesn't quite match the source code.
For example,
vrshrn.u32 -> vrshrn.i32
vrshrn.u16 -> vrshrn.i16
vadd.u16 -> vadd.i16
My questions:
Is this behavior correct and expected? If not, how do we correct it?
If they are equivalent, why do we nee need the unsigned ones at all? Is it because that way the code is more explicit?
Is this behavior expected with other platform's toolkit? For example, Android's toolkit? (I have heard Apple's AS is an ancient one)
These instructions don't depend on signedness of elements - that's actually what the .Inn suffix means. The assembler still accepts either .Snn or .Unn versions, but disassembly will only use .Inn.
For instructions which do differentiate between signed and unsigned integers (e.g. VMULL) the assembler won't accept the .Inn suffix, but only .Snn or .Unn.
They are the same instruction. The sign has no effect on the operation.
$ cat neon.s
.text
.code 32
.globl _foo
_foo:
vrshrn.u32 d0, q0, #1
vrshrn.i32 d0, q0, #1
$ otool -tv neon.o
neon.o:
(__TEXT,__text) section
_foo:
00000000 f29f0850 vrshrn.i32 d0, q0, #1
00000004 f29f0850 vrshrn.i32 d0, q0, #1
In general, you can be assured that assemblers do nothing crazy, unlike some compilers.
When the assembler alters some instructions, it's mostly the exact equivalent or pseudo-insturction.

ESC/P programming!

Why i need to use it is because for some printers using TPrinter prints some weird hieroglyph at the beginning of the printable area.
My problem is that if i send some commands, nothing happens.
ESC E (#27 #69) - Sending this escape sequence didn't work as i expected. It removed first letter and rest of the string made bold. eg. Hello -> ello. After i changed it to ESC E ESC (#27 #69 #27), it worked fine. This example i managed to figure out, but...
trying to select character table "ESC t n" (#27 #116 n), to make "õäöü" work. This command just doesn't work. Nothing happens! And this command is supported by esc/p, esc/p 2 and 9-pin esc/p, so it should work just fine.
Manual can be found here.
If anyone has ever needed to use esc/p commands then maybe one can shed some light how to work with them!
Thanks in advance!
EDIT:
In my previous post i asked more or less the same question though answers were about how did i send commands to the printer. (I'll change my question there according to what was the answers!)
I accepted Ken's answer, because he claimed that the way i transferred the commands wasn't the best and i got it to work with Escape command.
The problem was that after trying to use my program with another printer, it didn't work as expected, because it uses TPrinter.Begindoc and EndDoc.
So actually i must use the other solution that Rob Kennedy helped me with!
EDIT 2:
As it turned out, i used wrong manual, where commands are little different (though still supporting esc/p as it proclaims). Thank you all for your help!
PS!
I still have a question: I need a character table where
245 = õ
228 = ä
246 = ö
252 = ü
which is iso 8859. But in manual there is no such character table or any similar to it. Should i do some string manipulation and replace eg 228 to 132 or does anyone know any better approuch?
I keep it unanswered for a while, and then accept stukelly's answer.
Based on your previous question, I think you are using the wrong commands to control the EPSON TM-T70 receipt printer. After some research I found the product brochure and POSMicro both mention ESC/POS.
The ESC/POS command for turning bold on and off requires has a third value, as follows.
ASCII ESC E n
Hex 1B 45 n
Decimal 27 69 n
Where n is 0 or 1, turning bold off or on.
Here is a detailed ESC/POS reference.

Prolog: Making a procedure to print Hello World

I want to load this simple something into my Editor:
Write:-repeat,write("hi"),nl,fail.
So that it prints "hi".
What should I do?
I'm currently trying to do File->New
and Saving a file named Write into E:\Program Files\pl\xpce\prolog\lib
When doing the query:
?-Write.
It's printing:
1 ?- Write.
% ... 1,000,000 ............ 10,000,000 years later
%
% >> 42 << (last release gives the question)
Why?
EDIT
I did some more research. Apparently this is what SWI-Prolog does when you ask it about an uninstantiated variable.
$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.6.64)
Copyright (c) 1990-2008 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- X.
% ... 1,000,000 ............ 10,000,000 years later
%
% >> 42 << (last release gives the question)
?-
UPDATE
Changing the name to lowercase works. Uppercase is for variables:
helloworld.prolog:
helloworld:-write('Hello World!'),nl,fail.
Then:
$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.6.64)
Copyright (c) 1990-2008 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- ['helloworld.prolog'].
% helloworld.prolog compiled 0.00 sec, 1,376 bytes
true.
?- helloworld.
Hello World!
false.
?-
Notice that you have to consult the file first. I tried this out and it works for sure.
You need to name the procedure write, not Write. Upper case starting letters are for variables. (It might be less confusing if you call it something else like writeHi or something, so it doesn't have the same name as a built-in procedure, but it will still work when you call it write because your write has a different arity than the built in one).
Also you might want to replace "hi" with 'hi', though it will work either way (but only the second version will actually print the word hi to the screen - your version will print it as an integer list).

Resources