tonyg changed the topic of #racket to: The Racket Programming Language -- https://racket-lang.org/ -- https://gather.town/app/wH1EDG3McffLjrs0/racket-users -- http://pasterack.org -- logged at https://libera.irclog.whitequark.org/racket/ -- This is the right place to ask for help with (Dr)Racket. Remember to wait around for an answer!
badkins 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
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> ohh interesting! On windows?
<epolanski> Ubuntu 22.04
<winny> I wrote a little toy program that does use the fancy features of the readline library, to demonstrate how one might use it https://gist.github.com/winny-/85ef59bf1933681d59aa7d08494856e5
<epolanski> Ubuntu 22.04 running on WSL 2 running on Windows 10. Took me ages to setup VS Code to work with racket.
<epolanski> winny, thanks, I'll take a look at it
<epolanski> does these libraries all have a typed/ version?
<winny> just for fun, what happens if you run racket -e '(port->string)' then type some text, then press return, then type control-d (EOF)?
<epolanski> I chose Racket for its static typing features, even though I understand Racket does not support HKTs properly
<epolanski> I'll try
<epolanski> this happens
<winny> that looks good
<epolanski> what's (EOF) anyway?
<winny> so if you run: `racket -e '(read-line)'` type some text, then type return, do you get the string you typed back?
<epolanski> that's the output
<winny> End of File. it's a special value that indicates there's no more data to be read
<winny> great! that's good output
<epolanski> About the text output, why does it include the return carriage?
<winny> i am not sure if all libraries that ship with racket have a typed variant... a large majority do
<epolanski> I mean, in this example: (define name (read-line (current-input-port) 'linefeed))
<epolanski> and when I later output it with (write name)
<winny> what's the output you get with (write name) ?
<winny> I think Typed Racket does offer HKT in the form of polymorphic types (like generics in a way) https://docs.racket-lang.org/ts-guide/types.html#%28part._.Polymorphic_.Data_.Structures%29
<winny> im not familiar with HKT other than a quick google, so i may have misunderstood
<epolanski> "Hello"⏎
<epolanski> that's the output of write when feeding Hello (without typing the quotes)
<winny> hmmm, could you share a screenshot of the terminal session?
<winny> thx
<winny> are you by chance using zsh?
<epolanski> fish shell
<winny> ahh
<epolanski> I'll try in bash
<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
<winny> For comparison this is how it appears in zsh (with a similar feature) https://i.imgur.com/YqFYMuO.png
<epolanski> I see displayln does not show the quotes
<winny> https://docs.racket-lang.org/guide/read-write.html some helpful side-by-side examples on this page
<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
badkins has joined #racket
badkins has quit [Ping timeout: 244 seconds]
ec has quit [Ping timeout: 258 seconds]
xgqt has quit [Ping timeout: 252 seconds]
codingquark has quit [Ping timeout: 268 seconds]
ec has joined #racket
codingquark has joined #racket
ec has quit [Remote host closed the connection]
ec has joined #racket
badkins has joined #racket
sxn has joined #racket
sxn has quit [Client Quit]
badkins has quit [Ping timeout: 260 seconds]
sxn has joined #racket
sxn has quit [Client Quit]
sxn has joined #racket
sxn has quit [Client Quit]
sxn has joined #racket
sxn has quit [Client Quit]
sxn has joined #racket
sxn has quit [Client Quit]
sxn has joined #racket
sxn has quit [Quit: sxn]
sxn has joined #racket
ur5us has quit [Ping timeout: 244 seconds]
sxn has quit [Quit: sxn]
sxn has joined #racket
<jA_cOp> epolanski: about (read-line (current-input-port) 'linefeed), those are the default arguments, so you can just call (read-line). See https://docs.racket-lang.org/reference/Byte_and_String_Input.html?=read-line#%28def._%28%28quote._~23~25kernel%29._read-line%29%29
xgqt has joined #racket
jao has joined #racket
<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> the following code:
<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")
badkins has joined #racket
<winny> https://github.com/winny-/tinybasic.rkt/blob/master/tinybasic-lib/main.rkt#L21 here's one that takes -r, -k, -i and an optional filename
<winny> n.b. ignore my weird usage of *names* (it's not idiomatic racket)
<jA_cOp> indeed, the docs can be really dense; make sure to also check out the example from the racket/cmdline docs, I always use it as a quick reference: https://docs.racket-lang.org/reference/Command-Line_Parsing.html
<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
sxn has quit [Client Quit]
<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> not the most intuitive, #:args essentially uses the general function argument syntax: https://docs.racket-lang.org/guide/lambda.html
<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 :)
<jA_cOp> winny: not quite it, but a Github search seems to yield quite a few examples! https://github.com/search?q=%22%28require+racket%2Fcmdline%29%22&type=code
<jA_cOp> a package search would probably have yielded better examples, though, a lot of those Github ones are not great :)
<winny> Hey, better than nothing, esp for free B-)
<jA_cOp> true, true
<winny> thinking about command-line reminds me of all the prereqs to getting it working in an idiomatic fashion
<winny> parameters, understanding the module system (or being told by somebody who does how to define a main submodule), how to read the docs grammar
<winny> how to parse data out of strings robustly
<epolanski> thanks jA_cOp this is all very useful
<jA_cOp> 👍️
<epolanski> are there docs for the typed versions of those modules? kind of hard for me to read untyped docs
<jA_cOp> I could be wrong, but I don't think there is a typed version of racket/cmdline. You can use untyped modules from typed modules with require/typed: https://docs.racket-lang.org/ts-guide/typed-untyped-interaction.html
<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> ahh here we go, that's quite nice https://docs.racket-lang.org/ts-reference/special-forms.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._ann%29%29
<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]
ec has joined #racket
badkins has joined #racket