badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
morte_ has joined #racket
morte_ has quit [Ping timeout: 264 seconds]
monkey_ has quit [Ping timeout: 264 seconds]
monkey_ has joined #racket
cwebber has joined #racket
cwebber has quit [Ping timeout: 265 seconds]
FreeFull has quit []
monkey_ has quit [Remote host closed the connection]
jao has quit [Ping timeout: 264 seconds]
sagax has joined #racket
ur5us has quit [Ping timeout: 244 seconds]
badkins has joined #racket
badkins has quit [Ping timeout: 244 seconds]
skapata has quit [Remote host closed the connection]
chimp_ has quit [Ping timeout: 265 seconds]
ttree has quit [Ping timeout: 264 seconds]
epolanski has joined #racket
<epolanski>
Hello, I am new to Racket and trying to grasp basic input-output, I am attempting to read a line from the terminal and my current code looks like this:
<epolanski>
but when I `racket --repl --eval '(enter! (file "/foo.rkt"))' it gives me `readline: unbount identifier`
<winny>
Hey epolanski, the readline library lets you write interactive prompts that have history (up/down arrow), possibly tab completion, and text editing features
<winny>
are you looking for those features, or to simply read a line into the program?
<winny>
if the latter, you might prefer (read-line)
<epolanski>
I'm just trying the basics of the language so looking for the equivalent of writing a program like prompting the user for his name and returning "Hello" plus his name
<epolanski>
like string name = Console.Readline(); Console.WriteLine("Hello ", name); in C#
<winny>
Sure, in that case I think you might want (read-line), it's roughly equivalent to C#'s ReadLine()
<epolanski>
I'm looking at the examples in the docs for `read-line` and none seems to actually prompt me for a line
<epolanski>
Ok I think I sorted it out: (define name (read-line (current-input-port) 'linefeed))
<winny>
i think what might be happening is the shell is detecting the program exited with text on the final line it outputted (and no final newline)... so the shell inserts an indicator
<epolanski>
interestingly, doesn't go on a newline after "Hello"
<winny>
I know zsh does this, maybe fish does this too
<winny>
what happens if you run this in fish: printf 'hello world'
<plane>
yes, you can see that if you try echo "hi" versus echo -n "hi" in fish
<epolanski>
okay so basically, let me recap. My write procedure in racket does not include a newline. Thus it prints whatever I inserted in the prompt and the shell inserts an indicator (in fish) while stays on the same line (in sh/bash)
<plane>
there are variants of write, print, and display called writeln, println, and displayln
ur5us has joined #racket
<winny>
yep, fish detects the unterminated line and appears to indicate with that return symbol. Whereas bash doesn't offer this feature (iirc)
<epolanski>
plane, yeah I see, I do have one last question, why is the written value quoted
<epolanski>
What if I don't want the double quotes in the output
<plane>
yes the docs discuss those functions in a couple places, but that is the page i personally found most helpful. i was about to link to it
<winny>
👀
<plane>
(as an aside for bash users, ble.sh does a lot of fish-y stuff, including that end-of-line feature we just talked about)
ur5us has quit [Ping timeout: 244 seconds]
<epolanski>
anybody using racket on vscode knows how to get type hints from code? I can't see the types of my code neither in racket nor typed/racket
<epolanski>
I'm using magic racket
<winny>
In case you want more reach, there's a discord with a #vscode channel (and a discourse forum) (See https://racket-lang.org/ 's community tab towards the bottom)
Psybur has joined #racket
ur5us has joined #racket
<bremner>
ugh, discord.
<winny>
yeah... maybe the discourse might be better to taste!
<bremner>
fwiw, discourse is working OK for me in mailing list mode
<epolanski>
jA_cOp: true, but in the first iteration (read-line) on its own did not work (maybe I mistyped something), and I also like to understand the parameters even if they are the defaults
badkins has joined #racket
badkins has quit [Ping timeout: 265 seconds]
codingquark has quit [Ping timeout: 265 seconds]
<epolanski>
I'm trying to use command-line from racket/cmdline but I'm not sure how to pass command line arguments
<epolanski>
if launched like racket /home/aquazi/bench/racket-experiments/foo.rkt -- hello returns foo.rkt: expects no arguments on the command line, given 1 argument: hello
<jA_cOp>
racket/cmdline is for advanced parsing, with support for flags, options, and automatic --help generation. If you just want the raw command line arguments, you can use the `current-command-line-arguments` parameter, e.g. `(displayln (current-command-line-arguments))`
<jA_cOp>
if you want to use racket/cmdline and enforce a single argument, you can do `(define arg (command-line #:args (a) a))`
sxn has quit [Ping timeout: 264 seconds]
<epolanski>
jA_cOp: but what I don't understand is this: foo.rkt: expects no arguments on the command line, given 1 argument: hello
<epolanski>
why would it fail with command-line?
<winny>
the docs are a bit dense, let's get some examples
<winny>
working on a framework to replace this and other stuff with more user friendly forms... but let's talk about command-line :)
<jA_cOp>
when you call (command-line) you are calling it with the defaults for all its arguments. For example, the name of the program defaults to foo.rkt, and the list of raw command line arguments defaults to (current-command-line-arguments). Further, supplying no "finish clause" (see docs for details) is the same as supplying #:args () (void)
<jA_cOp>
in other words, (command-line) says your program has no arguments, but you gave it one argument ("hello")
<epolanski>
oh so it is failing exactly because I'm using that
<epolanski>
indeed if I remove the command-line procedure it does not fail anymore, so command-line was indeed working, parsing the arguments and noticing that I didn't set it up to take any thus failing
<jA_cOp>
mhm!
<epolanski>
I like this pattern, feels very safe
<epolanski>
and less error prone
morte_ has joined #racket
<epolanski>
so this is what you meant when you said it's more advanced, it's more for whe nyou already know what kind of args you want to pass and how to parse them
<epolanski>
while I merely wanted to reprint any that I was passing without any logic
<jA_cOp>
yeah, it's advanced in the sense that it does a whole lot more work, but it's basic in the sense that I would definitely recommend using it instead of your own parsing logic when you have a typical CLI that command-line can handle! :)
sxn has joined #racket
<epolanski>
oh I'm just experimenting and learning some bits, I'm very new to racket jA_cOp
<jA_cOp>
mhm
<epolanski>
I have my checklist of trivial programs I use for new languages (reading and writing from terminal, reading files, writing files, parsing command line arguments, basic web server, stuff like this)
<epolanski>
After I implement those I generally feel more confident to learn the rest
<winny>
i wonder if there's a way to get a report or list of all packages that use racket/cmdline collection
<winny>
collection of specimen for free
<jA_cOp>
note that if you wanted to use command-line but handle a variable number of arguments after the flags, this is possible too, like so: `(define my-args (command-line #:args args args))`
<jA_cOp>
also note that command-line generates --help for you, and the output of `myprogram --help` shows an overview of the program's flags and arguments, so it can be useful to check you got it how you wanted :)
<winny>
interestingly, it appears there is a typed command-line macro ootb
<jA_cOp>
winny: where did you find it? I'm still pretty new to typed racket and I've no idea
morte_ has quit [Read error: Connection reset by peer]
<jA_cOp>
also, racket/cmdline has two bindings, `command-line` and `parse-command-line`. The former is a macro ("syntax") and the latter is a function. Using require/typed is probably straight-forward enough for the function, but I've no idea if or how it's possible when requiring macros
morte_ has joined #racket
<winny>
I opened up a typed/racket repl (racket -l typed/racket -i), then run (command-line) and it worked much to my surprise... then i tried something like this as a more complicated example to investigate the typing: (command-line #:argv (vector "a" "b" "c") #:args args args)
szkl has joined #racket
<winny>
unfortunately it seems args is bound as type (Listof Any)
<winny>
it may not be super precise on its types
<winny>
(you can fix this using `ann` to annotate the expression)
<samth>
winny: you want `#:args #{args : (Listof String}`
<winny>
ahh, thx
<jA_cOp>
that's cool. Is it just that... you can use macros from typed modules without require/typed and it just uses type inference? I don't remember reading anything about macros specifically in the typed racket docs, could be wrong though
<winny>
samth: is that a reader extension for TR? It's pretty concise looking
<samth>
winny: yes
<samth>
you can use that on any binding position
<samth>
(eg with `match` or other forms that don't have special TR versions)
<winny>
oops, just above actually, somebody here might be sleep deprived ;)
<epolanski>
ok I got it to work for a trivial case: (command-line #:args (a b) (displayln (string-append a " " b)))
<epolanski>
with two args
<epolanski>
let's see what else I can do, I like how it works, gonna port it to TypeScript :D
<epolanski>
very nice api
<jA_cOp>
I wouldn't be surprised if TS already had a similar library available, it's pretty common in my experience, e.g. Python's argparse, Rust's clap
badkins has quit [Remote host closed the connection]
badkins has joined #racket
comatory has joined #racket
kenran has joined #racket
badkins has quit [Remote host closed the connection]
kenran has quit [Quit: WeeChat info:version]
ttree has joined #racket
williewillus has joined #racket
skapata has joined #racket
<epolanski>
It's not just a matter of providing similar utils, but the same DX and API, in this I think cmdline has very good ergonomy jA_cOp
badkins has joined #racket
jao has quit [Remote host closed the connection]
jao has joined #racket
FreeFull has joined #racket
morte_ has quit [Ping timeout: 252 seconds]
jao has quit [Remote host closed the connection]
jao has joined #racket
jao has quit [Remote host closed the connection]
jao has joined #racket
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
morte_ has joined #racket
codaraxis__ has joined #racket
ur5us has joined #racket
codaraxis has quit [Ping timeout: 265 seconds]
badkins has joined #racket
badkins has quit [Ping timeout: 244 seconds]
epolanski has quit [Quit: Connection closed for inactivity]
monkey_ has joined #racket
monkey_ has quit [Ping timeout: 244 seconds]
morte_ has quit [Ping timeout: 244 seconds]
comatory has quit [Ping timeout: 244 seconds]
FreeFull has quit [Ping timeout: 264 seconds]
FreeFull has joined #racket
FreeFull has quit []
skapata has quit [Remote host closed the connection]
skapata has joined #racket
monkey_ has joined #racket
ec has quit [Ping timeout: 258 seconds]
badkins has joined #racket
badkins has quit [Remote host closed the connection]