I've been looking over the chat example here: https://nim-lang.org/docs/asyncnet.html
I was trying to make a const port number, like so:
const
PORT = 9000
server.bindAddr(Port(PORT))
However, I receive an error:
Error: attempting to call routine: 'Port'
found 'PORT' of kind 'const'
So looked at bindAddr's parameters: > proc bindAddr(socket: AsyncSocket; port = Port(0); address = "") {...}
Some questions:
- How come server.bindAddr(Port(PORT)) works, when the first parameter of bindAddr uses a socket, not a port?
- How come my const PORT isn't working?
Your PORT is colliding with Port, it literally says that, const dont need all uppercase names anyway.
Your server is a socket. Check nimpretty and nim check --styleCheck:hint on the terminal.
const portNumber = 9000
server.bindAddr(Port(portNumber))
const dont need all uppercase names anyway.
That is my style, I like my const names all uppercase
bindAddr has 3 parameters AFAIK, socket, port and address, correct? How come simply passing in Port(9000) works, instead of port = 9000?
I'm following the parameter guide from https://nim-lang.org/docs/tut1.html#procedures-named-arguments
Your server is AsyncSocket.
You can pass port = Port(9000) too.
Nim is style agnostic.
bindAddr(server, Port(9000)) will work too.
echo "a"
echo("b")
echo"c"
"d".echo
"e".echo()
Nim has UFCS.
Wow
server.bindAddr(Port(9000))
server gets passed to the first argument in the background? Then in my case, the next argument is port, which is the first argument. Interesting, but very confusing at first.
server gets passed to the first argument in the background?
We really should not name it this way, it is no magic. It was called UFCS in D-Lang and is called "Method Call Syntax" in Nim. f(x) can be written as x.f
https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax
https://nim-lang.org/docs/manual.html#procedures-method-call-syntax