andreiformiga
2018-5-10 15:46:01

is there a way to require a module from the REPL but with access to all its definitions (as in a module+)?


samth
2018-5-10 15:47:30

@andreiformiga you might like enter!


andreiformiga
2018-5-10 16:21:48

@samth thanks, that’s exactly what I was looking for (thought about something like :m+ in GHCi actually)


ghoetker
2018-5-10 20:31:51

As a beginner, I’d appreciate any feedback on the following short code snippet. It works, but I can’t shake the feeling that it is clumsy and perhaps really inefficient.

The goal is to generate pdfs-in-folder, a set of paths to all PDFs and ePubs contained in the folder previously defined as path-to-pdfs and its subdirectories.

(define pdfs-in-folder
  (list->set
   (for/list
       ([f (in-directory path-to-pdfs)]
        #:when (member (path-get-extension f) '(#".pdf" #".epub")))
     f)))

Thank you for any feedback on how to improve.


greg
2018-5-10 22:05:53

@ghoetker What you have seems good to me! Not inefficient. I probably wouldn’t bother doing list->set unless the guarantee of uniqueness were super important to the code using this. Depending on my mood I might split this into two functions so it reads more clearly (to me). Like maybe: (define (pdf-extension? filename) (member (path-get-extension filename) '(#".pdf" #".epub"))) (define (pdfs-in-folder path) (for/list ([f (in-directory path)] #:when (pdf-extension? f)) f))


ghoetker
2018-5-10 23:25:15

@greg Thank you so much. Splitting does improve readability. Set is nice because I later to a set-subtract to identify which of these files are not present in a list of expected files.


greg
2018-5-10 23:27:23

@ghoetker Oh in that case, I forgot — there’s a for/set you could use to produce that directly (no need to compose for/list with list->set).


andreiformiga
2018-5-10 23:35:41

I want a kind of “list” widget for lines of text. most of it can be done with a multiline text field but I need to highlight/select a line. I don’t see how to do that in racket/gui


greg
2018-5-11 00:30:58

@andreiformiga I have zero hands-on with racket/gui, but: 1. What about using a list-box%? That might be more understandable for users? 2. If you really want a multiline text-field%, then the docs say "get-editor returns the field’s editor, which provides a vast collection of methods for more sophisticated operations on the text", and one of those operations seems to be set-position: https://docs.racket-lang.org/gui/text_.html#%28meth._%28%28%28lib._mred%2Fmain..rkt%29._text~25%29._set-position%29%29


andreiformiga
2018-5-11 00:45:44

it’s a list box alright, looking in the widget gallery I thought it was some kind of a combo box


ghoetker
2018-5-11 03:23:23

Hoping for help with something well beyond my experience. I have the following plist. The information I wish to extract is about a quarter of the way down, "<string>A/Amemiya–1984-Tobit–00.pdf</string>". Searching the Racket documents revealed xml/plist. However, because I’ve not worked with parsing XML or plists before, I am stuck. If anyone could at least get me started, I would really appreciate it. Complete solutions also very welcome :smile:. Thank you very much.

<?xml version="1.0" encoding="UTF–8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" “http://www.apple.com/DTDs/PropertyList–1.0.dtd”> <plist version="1.0"> <dict> <key>$archiver</key> <string>NSKeyedArchiver</string> <key>$objects</key> <array> <string>$null</string> <dict> <key>$class</key> <dict> <key>CF$UID</key> <integer>7</integer> </dict> <key>NS.keys</key> <array> <dict> <key>CF$UID</key> <integer>2</integer> </dict> <dict> <key>CF$UID</key> <integer>3</integer> </dict> </array> <key>NS.objects</key> <array> <dict> <key>CF$UID</key> <integer>4</integer> </dict> <dict> <key>CF$UID</key> <integer>5</integer> </dict> </array> </dict> <string>relativePath</string> <string>aliasData</string> <string>A/Amemiya–1984-Tobit–00.pdf</string> <dict> <key>$class</key> <dict> <key>CF$UID</key> <integer>6</integer> </dict> <key>NS.data</key> <data> AAAAAAF8AAIAAAxNYWNpbnRvc2ggSEQAAAAAAAAAAAAAAAAAAAAA AAAAQkQAAf////8ZQW1lbWl5YS0xOTg0LVRvYml0LTAwLnBkZgAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//// /wAAAAAAAAAAAAAAAAABAAMAAAogY3UAAAAAAAAAAAAAAAAAAUEA AAIAOi86VXNlcnM6Z2hvZXRrZXI6QmliRGVza1BhcGVyczpBOkFt ZW1peWEtMTk4NC1Ub2JpdC0wMC5wZGYADgA0ABkAQQBtAGUAbQBp AHkAYQAtADEAOQA4ADQALQBUAG8AYgBpAHQALQAwADAALgBwAGQA ZgAPABoADABNAGEAYwBpAG4AdABvAHMAaAAgAEgARAASADhVc2Vy cy9naG9ldGtlci9CaWJEZXNrUGFwZXJzL0EvQW1lbWl5YS0xOTg0 LVRvYml0LTAwLnBkZgATAAEvAAAVAAIAD///AAA= </data> </dict> <dict> <key>$classes</key> <array> <string>NSMutableData</string> <string>NSData</string> <string>NSObject</string> </array> <key>$classname</key> <string>NSMutableData</string> </dict> <dict> <key>$classes</key> <array> <string>NSDictionary</string> <string>NSObject</string> </array> <key>$classname</key> <string>NSDictionary</string> </dict> </array> <key>$top</key> <dict> <key>root</key> <dict> <key>CF$UID</key> <integer>1</integer> </dict> </dict> <key>$version</key> <integer>100000</integer> </dict> </plist>