Print "open curly bracket" with lua - lua

I'm new to lua and I'm trying to print an open curly bracket { in the output screen. I tried these ones:
print "%{"
print "\u123"
print "{{"
And there was no luck, but if I try the close bracket there's no problem and it prints }.
I'm wondering how may I figure it out.

print "{" Should do the job.
#lhf already sugested.

Related

How to remove white spaces after "(" in string?

A lua newbie here.
I would like to replace the string '$\\psi\\left( y\\right)$' with '$\\psi\\left(y\\right)$' i.e. remove any white spaces that show up after ( and before the next non-white space character.
I have been trying gsub but each attempt did not work. This is what I tried
function foo(s)
print('before s = '..s)
str=string.gsub(s,"\\left( ","\\left(")
print('after s= '..str)
return str
end
And tried
function foo(s)
print('before s = '..s)
str=string.gsub(s,"\\left(%s+","\\left(")
print('after s= '..str)
return str
end
And few other variations. But each time I call the function as follows
foo('$\\psi\\left( y\\right)$')
The string returned is the same. The white space is still there.
What is the correct way to do this? Using Lua 5.2.4 on linux.
I intend to use this function inside lualatex, and these strings will be passed from latex to lua as strings. But I am now trying this function in standalone lua installation on Linux first to see if it works before I use it inside Lualatex.
Magic characters like ( need to be escaped.
Please refer to https://www.lua.org/manual/5.3/manual.html#6.4.1
Replace "\\left(%s+" with "\\left%(%s+" or "\\left( +" with "\\left%( +"
Looks to me like some bug. This should actually result in an "unfinished capture" error. At least it would if ( was the first character in the pattern.

How can I use single and normal quotation marks in the same string?

I am working on a project, in which you type your input sentence, and I need to be able to use " and ' in the sentence, such as Input = "I said, "Hi what's up?" print(Input) in which I get an error. If anyone knows how to fix this that would be great.
See https://www.lua.org/pil/2.4.html. Lua has very interesting feature to declare string with square brackets:
input = [[I said, "Hi what's up?"]]
input = "I said, \"Hi what's up?\""
input = 'I said, "Hi what\'s up?"'
I will tell some things in addition to what #Darius told above
When you tried to add a quatation mark inside a string, the lua interpreter get confused and break your string after the next quation mark without reaching the end of the line. That's the reason for the error.
Try to understand it by the following code
str = "Hello I"m somebody" -- here the interpreter will think str equals to "Hello I" at first, and then it will find some random characters after which may make it confused (as m somebody is neither a variable nor a keyword)"
-- you can also see the way it got confused by looking at the highlighted code
--What you can do to avoid this is escaping the quotes
str = "Hello I\"m somebody" -- here the interpreter will treat \" as a raw character (") and parse the rest.
You can also use the escape character () with others such as \', \", \[, \n (newline character), \t (tab) and so on.

Netlogo print values and text in the same line

I know how to print a variable and a text but I want to make it in the same line, If i Use:
print "text" MYVARIABLE
I got an exception
Expected command
So the question is: there is a way to print text and variable on the same line?
Thank you
Yes! The word primitive is what you are after- see the dictionary definition here.
In brief, you can follow the syntax:
print word "Count turtles: " count turtles
Or
print ( word "There are " count turtles " turtles right now" )

Print without newline

In BASIC I know of two instructions to print to the screen, PRINT, and WRITE, both of which automatically print strings with a newline at the end. I want to print a string without a newline. How can I do this? I'm using GW-BASIC.
Using PRINT with a semicolon will not print a new line:
10 REM The trailing semicolon prevents a newline
20 PRINT "Goodbye, World!";
Source: Rosettacode

print carriage return (not line feed) in erlang?

Wondering if it's possible to print a carriage return without a line feed in erlang? i.e. equivalent to printf("this will be replaced next time \r"); in C.
Had a look through the io:format() documentation and didn't see anything. It only seems to support ~n, equivalent to carriage return+line feed pair ('\n' in C).
Thx.
"\r" is a perfectly valid escape sequence in Erlang. So you can do just
io:format("\r").
Check the reference manual for other escape sequences.
You can use \r in a string for the return character so:
io:format("Counter value: ~b\r", [Counter])
This is also works for character constants, $\r, and in quoted atoms.
Doh. Answer came almost as soon as I posted. ~c enables printing of ASCII characters, so it's just a case of printing ASCII carriage return (13). e.g.
io:format("Counter value: ~b~c", [Counter,13])
Still interested in anything more elegant...
Thx.

Resources