
@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.

@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.

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))
_ ...))
'()) ...)))
_)
;; ...
)])

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.

@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.

I almost went that route. :slightly_smiling_face:

what about xml/path
? does that work?

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:

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

Hahahaha, fair enough.

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

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

Wow. Nice. (Hilarious name.)

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

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

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.

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

:slightly_smiling_face:

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

Ooh, three-star code.

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

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

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

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

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

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