yilin.wei10
2020-8-12 20:53:28

How do people deal with platform dependent code on racket?


yilin.wei10
2020-8-12 20:54:05

(Thinking for libraries etc…)


samth
2020-8-12 20:55:09

What kind of platform-dependent code?


samth
2020-8-12 20:55:50

The simplest answer is (if (eq? 'windows (system-type 'os)) ... ...)


yilin.wei10
2020-8-12 20:58:13

Ah - I’m touching GFX libraries so unfortunately things like vendor code (wayland vs. x, etc…)


samth
2020-8-12 20:59:07

Right, but what kind of conditional do you need? Is if enough, or do you need to compile some files only on some platforms or …?


samth
2020-8-12 20:59:25

You might look at racket/gui for inspiration, because that has a lot of platform-dependent code


yilin.wei10
2020-8-12 21:02:22

Just if I think would be fine mostly - the question comes from not understanding how racket distributes code at all (is it source based? Is there some intermediate format?). I’ll take a look at the racet/gui thanks.


samth
2020-8-12 21:10:18

I’m not sure what you mean by “how racket distributes code”. For example, there are a bunch of binary downloads for on http://download.racket-lang.org\|download.racket-lang.org. Those contain a lot a Racket code. The compiled Racket BC versions use a portable bytecode format for compiled Racket code, which is the same on all platforms. The Racket CS versions use a format that embeds machine code, and is different on different platforms. It’s also possible to create Racket CS compiled files that use a portable format and then are compiled to the non-portable format at installation time.


samth
2020-8-12 21:11:16

If you build an application with Racket, then there are of course lots of ways to distribute it. One popular way is using raco exe and raco distribute which bundles together your program and the Racket executable; that’s of course platform specific just like the executable is.


samth
2020-8-12 21:11:53

Those questions don’t really come into play when you’re talking about what you write in the source code, though.


yilin.wei10
2020-8-12 21:18:35

So when I run raco pkg install does it essentially download the source and compile to the byte code on my system?


samth
2020-8-12 21:18:45

Yes