cky
2017-4-6 07:13:39

@leif I like the idea too. Probably precompute (log 2) and (log 10) and use those precomputed values when the base is 2 or 10.


cky
2017-4-6 07:16:09

@lexi.lambda So, the idea is an XML file like such:

<TextureAtlas imagePath="News.png" width="2048" height="512">
    <SubTexture name="event_frame_bottom" x="76" y="263" width="1494" height="217"/>
    <SubTexture name="event_frame_left" x="2" y="2" width="39" height="448"/>
    <SubTexture name="event_frame_right" x="43" y="2" width="31" height="448" frameX="-8" frameY="0" frameWidth="39" frameHeight="448"/>
    <SubTexture name="event_frame_top" x="76" y="2" width="1494" height="259"/>
</TextureAtlas>

has elements as well as PCDATA that consists only of whitespace. I could use eliminate-whitespace, but otherwise the only other approach is either some way of filtering out the PCDATA elements (which was what I ended up doing) or doing the or thing that doesn’t work.


cky
2017-4-6 07:17:32

Here’s the code I currently use:

  (match xml [(document _
                        (element _ _ 'TextureAtlas
                                 (list-no-order (attribute _ _ 'imagePath image-path)
                                                _ ...)
                                 (app (curry filter element?)
                                      (list (element _ _ 'SubTexture
                                                     (app (curry cons (attribute #f #f 'rotated "false"))
                                                          (list-no-order (attribute _ _ 'name names)
                                                                         (attribute _ _ 'x (app string->number xs))
                                                                         (attribute _ _ 'y (app string->number ys))
                                                                         (attribute _ _ 'width (app string->number widths))
                                                                         (attribute _ _ 'height (app string->number heights))
                                                                         (attribute _ _ 'rotated (app (curry string=? "true") rotateds))
                                                                         _ ...))
                                                     '()) ...)))
                        _)
;; ...
)])

cky
2017-4-6 07:18:21

Really, I can’t find any useful XML attribute-querying functions in Racket and so I’m resorting to using match to do attribute matching for me. Lol.


lexi.lambda
2017-4-6 07:25:19

@cky: your approach seems reasonable, though it does seem like an abuse of match. the sxml package seems to have support for xpath queries, though, if you need that.


cky
2017-4-6 07:25:48

I almost went that route. :slightly_smiling_face:


lexi.lambda
2017-4-6 07:26:28

what about xml/path? does that work?


cky
2017-4-6 07:30:04

That could be worth a try, too (in addition to the XPath approach you mentioned). I was hoping to be able to use something more lightweight, but I’m gathering that it doesn’t exist in the Racket world. :slightly_smiling_face:


lexi.lambda
2017-4-6 07:31:52

if I were reading data like that, I’d probably get it into a non-xml format asap, then work with the cleaned data


cky
2017-4-6 07:32:08

Hahahaha, fair enough.


lexi.lambda
2017-4-6 07:34:06

when I wrote Ruby for my job, I wrote a whole DSL for turning gross XML into POD https://github.com/lexi-lambda/decontaminate


lexi.lambda
2017-4-6 07:34:16

it’d be really easy to do something similar in Racket, I would imagine


cky
2017-4-6 07:34:42

Wow. Nice. (Hilarious name.)


cky
2017-4-6 07:35:15

Thanks for the pointers! Glad to know I wasn’t completely bonkers for trying the approaches I tried. :slightly_smiling_face:


leif
2017-4-6 12:58:29

@cky Yup. Basically, what I had in mind was something like: (log x y) = (/ (log x) (log y)) except it can be computed faster.


jerryj
2017-4-6 18:19:26

RE: USB, Racket, and (to a lesser extent), microcontroller programming: I’m starting to work on a language for a mcu programming tool. I’d like to present the full end-to-end system in racket. If you’re available to offer some USB/Racket advice, please let me know. Right now my plan is to either neglect the USB aspect, or just make a minimal FFI wrapper around whatever windows library is needed.


jerryj
2017-4-6 19:43:00

turns out the libusb dll and ffi/unsafe are extremely needs suiting, gosh racket is good.


samth
2017-4-6 19:49:13

:slightly_smiling_face:


jerryj
2017-4-6 19:57:53

actually i’m a little confused about how to bend ffi/unsafe to my will in this case: the C signature is ssize_t libusb_get_device_list(libusb_context* ctx, libusb_device*** list). I know from the racket docs that i would do a (_cpointer 'CTX) for the first parameter, its not immediately obviously from the docs how to handle the libusb_device ***list


stamourv
2017-4-6 19:59:25

Ooh, three-star code.


jerryj
2017-4-6 20:00:13

yeah >_< it expects a reference to a 2d array, so that might make it a bit easier? i see some stuff about arrays, so maybe that’s the answer


jerryj
2017-4-6 20:08:40

hmm yeah i think i need to do a (array-ptr (_array #t x y)) and pass that in.


jerryj
2017-4-6 20:37:42

hmm this is a lot more complicated than I thought it would be :<, anyways, thanks!


samth
2017-4-6 20:43:40

great advice/thoughts on being an open source maintainer: http://brson.github.io/2017/04/05/minimally-nice-maintainer


jerryj
2017-4-6 20:59:59

the “Say "yes”" section is brilliant, i’ve been doing something like that during face-to-face reviews, it is very effective.


jerryj
2017-4-6 21:00:37

Just the exercise of trying to convince yourself of the other person’s point of view is really valuable.