Write apostrophe sign in writeln function - Pascal - pascal

How can I print the apostrophe sign in Pascal using the writeln function?
Example:
writeln('My brother's book');
wouldn't work because s book is out of "writing" function, so the compiler returns an error:
Fatal: Syntax error, ")" expected but "identifier S" found
Fatal: Compilation aborted

According to the Free Pascal Reference: The single quote character can be embedded in the string by typing it twice:
writeln('By brother''s book');

In Dev-Pascal 1.9.2 you will need three ''', for example:
writeln ('My brother'''s book');

Related

VBS won't allow programming

I was doing some programming and I get an error message when I try and run it. my code:
MsgBox ("hi")
sleep (2)
MsgBox ("you ok" vbYesNo, "how are you?")
Select Case result
Case vbYes,
MsgBox ("that's good!")
Case vbNo, MsgBox ("sorry to hear that.")
End Select
Line: 3
Char: 18
Error: Expected ')' Source: Microsoft VBScript compilation error.
The problem is as the error says you have compilation issues but looking at the rest of the example code you also have other issues waiting to be corrected.
Missing argument syntax in MsgBox() Function:
Line: 3
Char: 18
Error: Expected ')' Source: Microsoft VBScript compilation error.
is because the Function MsgBox() expects arguments separated by a comma but the argument separator after "you ok" is missing causing the compiler to throw the exception.
Cannot use parentheses when calling a Sub:
When calling a procedure that doesn't return a value using brackets around multiple arguments passed to the procedure will cause;
Microsoft VBScript compilation error: Cannot use parentheses when calling a Sub
There is a caveat to this which is if it's just one argument it will not fail to compile, but this isn't because it accepts one argument but because it sees the brackets as part of the argument not part of the procedure (Eric Lippert discusses this at length in his blog);
MsgBox("Hi") 'Will work
This is equivalent to writing;
Call MsgBox(("Hi")) 'Note the extra brackets
This can be a little confusing so when it comes to multiple arguments you might think this is ok;
MsgBox("you ok", vbyesno, "how are you?") 'This will error
But as the brackets now denote the argument parentheses it becomes invalid and throws a compilation error. To avoid this there are three things you can do;
Remove the parentheses
MsgBox "you ok", vbyesno, "how are you?"
Return a value (if the procedure can return a value)
result = MsgBox("you ok", vbYesNo, "how are you?")
As you check the value of result on the next line this would be the correct option as it result will contain the outcome of clicking either vbYes or vbNo in the MsgBox() function.
Use the Call statement to prefix the procedure call
Call MsgBox("you ok", vbYesNo, "how are you?")
Syntax Error:
Microsoft VBScript compilation error: Syntax error
This comes down to trailing commas after the Case arguments, just remove the commas and the code will compile.
Select Case result
Case vbYes
Call MsgBox("that's good!")
Case vbNo
Call MsgBox("sorry to hear that.")
End Select
The Sleep duration:
The Sleep() function expects a value expressed in milliseconds not seconds, at the moment the example code is waiting for 0.002 seconds. To wait for 2 seconds (which I'm assuming was the intention) use;
Call Sleep(2000)
Useful links
Answer to Can't Use Parentheses When Calling a Sub - VBScript

Bash script sourcing config file but can't use vars in arithmetic

This is killing me. I have a config file, "myconfig.cfg", with the following content:
SOME_VAR=2
echo "I LOVE THIS"
Then I have a script that I'm trying to run, that sources the config file in order to use the settings in there as variables. I can print them out fine, but when I try to put one into a numeric variable for use in something like a "seq " command, I get this weird "invalid arithmetic operator" error.
Here's the script:
#!/bin/bash
source ./myconfig.cfg
echo "SOME_VAR=${SOME_VAR}"
let someVarNum=${SOME_VAR}
echo "someVarNum=${someVarNum}"
And here's the output:
I LOVE THIS
SOME_VAR=2
")syntax error: invalid arithmetic operator (error token is "
someVarNum=
I've tried countless things that theoretically shouldn't make a difference, and, surprise, they don't. I simply can't figure it out. If I simply take the line "SOME_VAR=2" and put it directly into the script, everything's fine. I'm guessing I'll have to read in the config file line by line, split the strings by "=", and find+create the variables I want to use manually.
The error is precisely as indicated in a comment by #TomFenech. The first line (and possibly all the lines) in myconfig.cfg is terminated with a Windows CR-LF line ending. Bash considers CR to be an ordinary character (not whitespace), so it will set SOME_VAR to the two character string 2CR. (CR is the character with hex code 0x0D. You could see that if you display the file with a hex-dumper: hd myconfig.cfg.)
The let command performs arithmetic on numbers. It also considers the CR to be an ordinary character, but it is neither a digit nor an operator so it complains. Unfortunately, it does not make any attempt to sanitize the display of the character in the error message, so the carriage return is displayed between the two " symbols. Consequently, the end of the error message overwrites the beginning.
Don't create Unix files with a Windows text editor. Or use a utility like dos2unix to fix them once you copy them to the Unix machine.

What does "unterminated quoted string meets end of file" mean in MacVim?

I'm looking a way to compile Ruby code on OSX. I am using MacVim, and my code says:
puts "test"
I type rubydo %, and I get an error message SyntaxError: eval:1: unterminated quoted string meets end of file. What am I doing wrong?
Vim's rubydo command executes a command. You may have thought it was a filename (and used "%" as the parameter, i.e., the current buffer). The % is ruby's alternate string delimiter, and depending on how rubydo is implemented, the bare "%" could be mistaken for the beginning of a string.
The % Notation (Ruby Programming)
Vim documentation: if_ruby

"Unrecognized character \xE2" in a Hello World program

I am trying to write my first perl "hello world" program on Mac OS X Yosemite and it shows this error when I try to run this using terminal:
Unrecognized character \xE2; marked by <-- HERE after
print <-- HERE
near column 7 at test.pl line 4.
I couldn't figure out what was wrong in this program. Please help me out here.
Code:
#!/usr/bin/perl
use strict;
use warnings;
print “Hello world”;
Change the “” character in the print statement to "
Example
print "Hello world";
Make sure syntax like this ' should be proper. Check your perl file for syntax errors
perl -c testfile.pl
While it is not directly connected to this case, there's also a different situation when \xE2 error can appear, which can seem not obvious. One can also have a zero-width space in their string, which can also raise this error.
I couldn't see this character in notepad or notepad++, but I could see it in vim as <200b>. This character can be placed next to { and } characters when copying stuff from for example Microsoft Teams.
This link appears as the first one when searching for this kind of problem, so I thought it might be a good idea to post the solution here.

What is "Syntax Error, unexpected tCONSTANT" error in Ruby?

I am currently on Lesson 9 in "Learn Ruby the hard way".
I have typed the the line number 6 exactly as the way its being instructed but still I am getting error while executing.
It says:
Syntax error, unexpected tCONSTANT, expecting $end
puts " Here ^ are the days : ", days
You have forgotten to close a string on a previous line. Here's the problem reproduced:
paul#paulbookpro ~ ⸩ ruby
days = "abc
puts "Here are the days"
-:2: syntax error, unexpected tCONSTANT, expecting $end
puts "Here are the days"
^
It's treating the double-quote before the word "Here" as the closing quote of the string on the previous line, and then wondering why you're using a constant called Here (token beginning with upper case letter).
The error message means that the ruby parser encountered a constant (i.e. an identifier starting with a capital letter) where it did not expect one (specifically the parser expected the file to end at that point).
Since the code you've shown does not even contain a constant, the problem is likely caused by another part of your code.

Resources