Fork me on GitHub
#beginners
<
2024-05-12
>
Stef Coetzee13:05:32

Suppose a basic REPL is started from the command line with clj and a command is entered partway. How can the current command be interrupted and the prompt returned? (Ctrl+C closes the REPL entirely.)

clj
user=> (+ 1 ; how to interrupt this command and return to the 'user=> ' prompt?

Stef Coetzee13:05:20

Is there a keyboard shortcut to interrupt the current command?

dpsutton13:05:00

I don’t believe there is. You can use Ctrl-a to go to the beginning of the line and Ctrl-k to kill the lines.

👍 1
Stef Coetzee14:05:42

Thanks! Just typed a command as part of the FlowStorm tutorial and realized I wasn't aware of interrupting to return the prompt from the command line. I realize this isn't the regular workflow. Just thought I missed something as Ctrl+C does the trick in other languages' REPLs.

dpsutton14:05:08

yeah i think that’s a decent feature request

bibiki13:05:08

maybe close the parenteses, and run return. this may give you an error and get you back to your prompt. or just delete everything you have typed in already

Stef Coetzee13:05:45

Thanks. Curious to know whether there is a keyboard shortcut to interrupt the current command.

bibiki13:05:49

ctr+U will delete everything. if you mean interrupt a running command, I do not know of any shortcut though I'd expect there is one and hopefully somebody that knows will let us both know

seancorfield17:05:27

@UK6G9FSDR please use threads when replying to posts, instead of answering in the main channel.

bibiki17:05:33

@U04V70XH6 note taken. sorry, about that

1
Melody18:05:34

I have a noob question about WSL - I made a whole application using WSL for the first time last week. I had made it under a directory "/mnt/wsl/programming/May_2024/clojure_projects/first_webapp" and I shut down my computer to clean it and when I rebooted today my files are gone. Does anything under the WSL directory get deleted on restart? How can I avoid this happening? Also is my project gone or is there a way to recover that data? It was small obviously so I can just restart, but I don't want to keep making files that will just get deleted when I restart. An added note is that if I use the "code" command to bring up vscode in WSL, it still shows my old directory path there but it says it cannot navigate there because the file doesn't exist. I don't know how it can remember the path but not the file(s).

seancorfield18:05:20

When you start a WSL terminal, you would normally be in /home/<user> (for your default user when you set it up). I have a clojure folder in /home/sean and all my projects are in there. I am not sure what /mnt/wsl is but I've never used that. /mnt/c is your Windows C: drive accessible from Linux.

seancorfield18:05:44

In VS Code, I see a green WSL: Ubuntu bar in the lower left, without "Restricted mode".

Melody19:05:56

when i created that directory I had specifically thought I needed to save my files in the wsl directory... Now after researching it seems like that is just temporary storage that resets upon restart. The reason I thought I shouldn't do that is because they are windows partitions so I was under the impression that this "wsl" directory was effectively a virtual linux partition, which I suppose it is, but just temporarily? I am now understanding that I can save all my files to the regular /home/ directory because they will be saved there. I think I do need to restart my project but now I know that at least. As far as the restricted mode... Maybe I opened ubuntu not as an admin? I will try reopening it is an administrator and see if it works... Okay I turned off restricted mode and am running as admin and it is still an orange/brown ubuntu logo. I remember it being green at one point so I am not sure what is up with that. I tried googling it and didn't find much so far. I am going to take a break for now but hopefully I can figure it out later today.

seancorfield19:05:02

You don't need to run the terminal as admin. The "restricted mode" is probably VS Code checking that you trust the folder you are opening?

seancorfield19:05:33

VS Code asks about trust every time you open a new folder I think...

seancorfield19:05:20

Yeah, here we go:

seancorfield19:05:54

I created a brand new folder, started VS Code on that folder, and it asked me if I trust the author (otherwise it will open in "restricted mode").

seancorfield19:05:54

I've told it to trust my whole clojure folder so I can create new project folders inside there and it no longer asks. But if I create a new folder elsewhere, it will ask about trusting the author.

Melody00:05:08

Thank you for this detailed response!! I am going to get back to it soon and now that I know that I will make sure I save everything correctly.

Noah Bogart21:05:53

clojure.pprint/code-dispatch uses class and not type. i'd like to pretty-print a custom deref (my.custom/deref a) the same as (clojure.core/deref a). is that possible?

Bob B21:05:36

I'm a little confused by some pieces of the question... clojure.core/deref is a function that gets a value from something deref-able, so it's also not a type or a class. If the thing returned by my.custom/deref implements IDeref, then, barring any conflicts, it should print the same.

Noah Bogart21:05:20

in clojure/pprint/dispatch.clj, pprint-simple-list checks if the first element in the list is a reader macro symbol and prints specially for those cases. it uses a private map "reader-macros" to track those.

Noah Bogart21:05:10

@U013JFLRFS8 i'm discussing printing code-as-data using clojure.pprint/pprint

Bob B21:05:39

In that case, I don't think so. If you think about round-tripping it, if multiple things became @ when printing, it would be ambiguous at read-time.

print:
(clojure.core/deref a) -> @a
(my.custom/deref a) -> @a

read:
@a -> ??? could be either

Noah Bogart22:05:38

generically, that's a good point. in my case, i'm building a clojure linter (#C04SCGV2ATX) and use alternative versions of the reader macros to track when things are reader macros vs written literally (using the "symbol name"), so i need to differentiate when printing

Noah Bogart22:05:12

maybe the answer is to fork pprint's code printing for my library

hiredman23:05:48

You can just use methods to get all the functions for each dispatch value in the multimethod, then install the same function for your custom type

👍 1
Bob B23:05:02

or even have your own multimethod that handles your special cases specially, and calls pprint or whatever for everything else

👍 1
jpmonettas12:05:31

@UEENNMX0T maybe you can hack it like :

(alter-var-root #'clojure.pprint/reader-macros assoc 'my.custom/deref "@")

(pp/pprint '(clojure.core/deref a)) ; => @a  
(pp/pprint '(some.other/deref a))   ; => (some.other/deref a) 
(pp/pprint '(my.custom/deref a))    ; => @a 

👍 1